RemoteEvent Not Working For Healing Tool

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. :))

1 Like

You’re setting the value of the variable, not the value of Humanoid.Health

Healing.OnServerEvent:Connect(function(player, tool, Health)
    local char = player.Character or player.CharacterAdded:Wait()
    local hum = char.Humanoid

	hum.Health = hum.Health + 10
	wait(.33)
	tool:Destroy()
end)
1 Like

Isn’t the variable already set in the LocalScript for the humanoid?

1 Like

Yea but the variable saved the value, not the property

It stores the value

1 Like

Oh okay.
The destroy works but the health doesn’t. ;-;

1 Like

Ok, then try

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)

please dont use remotes to heal players thats super insecure, I’m pretty sure you can just do tool.Activated on the server :pleading_face:

2 Likes

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

2 Likes

Thanks for telling me.
I’m left with this now:

local tool = script.Parent

tool.Activated:Connect(function()
	print("Activated")
	local humanoid = tool.Parent:FindFirstChild("Humanoid")
	humanoid.Health = humanoid.Health + 10
end)

The print statement works but the health doesn’t.
EDIT: The humanoid.Health works when it is - 10 but not + 10.

mind sending the rbxm file of the tool or anything so I can test with it?

Sure. Do you want me to make it a model and send it to you in messages?

actually nevermind, I made a tool and used the script you sent, I have no idea why that isn’t working, I’ll reply if i find out

Yeah it’s really odd. Thank you!

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)

3 Likes

Yeah, I was before.
Thank you!

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

Yeah, I was going to add that in a second. I was confused why it wouldn’t work before. :slight_smile:

Here’s one thing you can do,

humanoid:TakeDamage(-10)

This will then give the player -10 damage (10 health added to the player)

Hope this helped! :smiley:

1 Like