So this is a local script that is inside Starter Player, that has a Remote Event. when this script is ran when pressing R, it adds the health you need (Yay! :D) then takes away the health you gained seconds later, to return to health back to its original percent. (No! D:) If anyone could help with this, that would be great.
local repStorage = game:GetService("ReplicatedStorage") local remote = repStorage:WaitForChild("HealEvent") remote:FireServer("argument") game:GetService("UserInputService").InputBegan:Connect(function(key) if key.KeyCode == Enum.KeyCode.R then game.Players.LocalPlayer.Character.Humanoid.Health = game.Players.LocalPlayer.Character.Humanoid.Health + 99 end end)
This is in a local script which means that changes you make to the properties of the humanoid are not replicated to the server. The reason you have run into this problem is because the client changes the humanoid health while the server tells the client that the actual health is something different. The server's instance of the health takes higher precedence so the health is immediately changed back.
If you want to fix this, you will have to change the health on the server. Create another remote event in replicated storage and fire it whenever the key R is pressed.
The reason why it changes the health back is because you are doing it on the client, not the server. Here is the code to do this:
Client Code:
local repStorage = game:GetService("ReplicatedStorage") local remote = repStorage:WaitForChild("HealEvent") local remote2 = repStorage:WaitForChild("HealEvent2") remote:FireServer("argument") game:GetService("UserInputService").InputBegan:Connect(function(key) if key.KeyCode == Enum.KeyCode.R then remote2:FireServer() end end)
Server Code:
HealthTakesAway = 99 game.RelicatedStorage.HealEvent2.OnServerEvent:Connect(function(plr) if workspace:FindFirstChild(plr.Name) then workspace[plr.Name].Humanoid.Health = workspace[plr.Name].Humanoid.Health + HealthTakesAway end end)
Hope this helped you :)