I'm making a first aid kit and it almost all works properly, adds to the players health but as soon as it adds to the players health less than a second later the players health goes back down to where it originally was.
local Tool = script.Parent local Player = game:GetService("Players").LocalPlayer.Name local healAmount = 30 local sound = script.Parent:FindFirstChild("FirstAid") print(Player) Tool.Equipped:Connect(function(Mouse) Mouse.Button1Down:Connect(function() print("Button1Down") local Playeruser = game.Workspace:WaitForChild(Player) local humanoid = Playeruser:FindFirstChildWhichIsA("Humanoid") local currentHealth = humanoid.Health local newHealth = currentHealth + healAmount humanoid.Health = newHealth sound:Play() wait(3.344) Tool:Destroy() end) end)
Could someone tell me why? Thanks!
You should be doing this on the Server, not Client.
local Tool = script.Parent local healAmount = 30 local Sound = Tool:WaitForChild('FirstAid') local beenUsed = false local Players = game:GetService('Players') Tool.Activated:Connect(function() if beenUsed then return end -- can only use once beenUsed = true local Player = Players:GetPlayerFromCharacter(Tool.Parent) if Player then if Player.Character and Player.Character:FindFirstChild('Humanoid') then local Humanoid = Player.Character.Humanoid Humanoid.Health = Humanoid.Health + healAmount Sound:Play() wait(Sound.TimeLength) Tool:Destroy() end -- core checks end -- player check end) -- onEquipped