local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StoneHealthRemoverEvent = ReplicatedStorage:WaitForChild("StoneHealthRemover")
local stoneFolder = game:WaitForChild("Workspace"):WaitForChild("Stones")
StoneHealthRemoverEvent.OnServerEvent:Connect(function(player, toolDamageValue, target)
local targetHealthValueInt = target:FindFirstChild("HealthValue")
local newHealthValue = targetHealthValueInt.Value - toolDamageValue
targetHealthValueInt.Value = newHealthValue
if targetHealthValueInt.Value <= 0 then
target.Parent = ReplicatedStorage
wait(5)
target.Parent = stoneFolder
end
print(newHealthValue)
end)
#How to set int value back to the original value after it been changed by a statement?
6 messages · Page 1 of 1 (latest)
This is the server sided script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StoneHealthRemoverEvent = ReplicatedStorage:WaitForChild("StoneHealthRemover")
local stoneFolder = workspace:WaitForChild("Stones")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local character = player.Character or player.CharacterAdded:Wait()
local rootPart = character:WaitForChild("HumanoidRootPart")
local function getEquippedTool()
for _, item in pairs(character:GetChildren()) do
if item:IsA("Tool") then
return item
end
end
return nil
end
mouse.Button1Down:Connect(function()
local target = mouse.Target
local equippedTool = getEquippedTool()
if target and target:IsDescendantOf(stoneFolder) and equippedTool and equippedTool:FindFirstChild("DamageValue") then
local equippedToolValue = equippedTool:FindFirstChild("DamageValue")
print(equippedToolValue.Value)
local allowedDistance = (rootPart.Position - target.Position).Magnitude
if allowedDistance <= 10 then
StoneHealthRemoverEvent:FireServer(equippedToolValue.Value, target)
print(player.Name .. " Clicked on: " .. target.Name)
else
print("To far to be able to click!")
end
else
print("Player is not holding a pickaxe!")
end
end)
And this is the local script
The reason i just can't hardcode the value back is because i got diffrent stones in a folder with diffrent kind of health values
It is prob something so simple i'm just stuck