I’m making a healing tool in my game. Since it doesn’t work with a server script, it has to be in a local script with a remote event. I added the remote event, but everything works except the healing.
I’ve looked at Developer Hub, the DevForum and TheDevKing but I can’t find out why the event won’t work.
Here is the server script and the local script:
-- LocalScript
local tool = script.Parent
local RS = game:GetService("ReplicatedStorage")
local Healing = RS:WaitForChild("HealingEvent")
tool.Activated:Connect(function()
local Humanoid = tool.Parent:FindFirstChild("Humanoid")
local health = Humanoid.Health
Healing:FireServer(tool, health)
end)
--Server Script
local RS = game:GetService("ReplicatedStorage")
local Healing = RS:WaitForChild("HealingEvent")
Healing.OnServerEvent:Connect(function(player, tool, Health)
Health = Health + 10
wait(.33)
tool:Destroy()
end)
The tool:Destroy() works but not the Health = Health + 10 won’t. Anyone know why? Thanks. :))
local RS = game:GetService("ReplicatedStorage")
local Healing = RS:WaitForChild("HealingEvent")
Healing.OnServerEvent:Connect(function(player, tool, Health)
local char = player.Character or player.CharacterAdded:Wait() -- get the player's character
local humanoid = char:WaitForChild("Humanoid") -- wait for the humanoid instance to exist, (if it doesn't)
Health = Health + 10
humanoid.Health = Health -- set the humanoid's heath to the "Health" variable
print(humanoid.Health, Health) -- to see the values
wait(.33)
tool:Destroy()
end)
It doesn’t really relate to your problem but your script can be used by exploiters for giving health. I recommend you to get the player health on the server side and not on the client side
Like i can just call Healing:FireServer(nil, 9999999) and i have my health.
Use the player for get the health on the Server Script
are you trying to test this by damaging yourself by changing your health in the explorer? I swapped to server rather than client and when I did that it fixed my health
so this is probably a visual bug, it should work normally
here’s a better way to do it btw
tool.Activated:Connect(function()
tool.Parent:FindFirstChild(“Humanoid”).Health += 10
end)
yw, also you might want to make a check if the health will be greater than the maxhealth, if people use it with 100 health they will wind up having 110 health