Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make my health restoring Tool work?

Asked by 5 years ago

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)
0
its replication, because ur doing it on the client User#23365 30 — 5y
0
just set it on the server using remove events User#23365 30 — 5y

1 answer

Log in to vote
0
Answered by
blockmask 374 Moderation Voter
5 years ago

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)
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 blockmask 374 — 5y
Ad

Answer this question