Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make my health restoring Tool work?

Hi!

I want my Tool to restore health to the player holding it when he clicks the left mouse button.

The problem is that it sets it back to what it was before after restoring health to the player. How do I prevent that?

Here is the code in my LocalScript (the parent is Tool):

script.Parent.Activated:connect(function()
	local player = game.Players.LocalPlayer
	local character = player.Character
	local hum = character.Humanoid
	if hum ~= nil then
		hum.Health = hum.Health + 20
	end
end)

2 comments

0

its replication, because ur doing it on the client

0

just set it on the server using remove events

1 answer

This is due to FE (Filtering Enabled). You would need to fire the server since that is from client-sided. I recommend you to look at some articles about filtering enabled.

But you would need to fire the server, and here is how you do this

--Server
local remote = pathToRemote

remote.OnServerEvent:Connect(function(plr, amount)
	if plr.Character.Humanoid then
		plr.Character.Humanoid = plr.Character.Humanoid + amount
	end
end)
--Client
local remote = pathToRemote
script.Parent.Activated:connect(function()
    local player = game.Players.LocalPlayer
    local character = player.Character
    local hum = character.Humanoid
    if hum ~= nil then
        remote:FireServer(20)
    end
end)

1 comment

0

Okay, I wrote that script fast, but you should check the amount of health given to the player, because exploiters can easily fire this remote event and give them health constantly

This discussion is preserved as it was. New answers, comments, and votes are closed.