Option 1
Well if you are going to do this on the client, use the UserInputService rather than the Mouse's KeyDown, as well as changing the deprecated connect to Connect
Revised Local Script
local player = game:GetService("Players").LocalPlayer
game:GetService("UserInputService").InputBegan:Connect(function(input, event)
if input.KeyCode == Enum.KeyCode.R then
player.Character:WaitForChild("Humanoid").Health = 100
end
end)
Option 2
However, I would suggest doing this on the Server since then the Health will change for the player for all others to see, and not just the client the local script is being used for:
Server Script under ServerScriptService
local remote = Instance.new("RemoteEvent")
remote.Name = "HealthReload"
remote.Parent = game:GetService("ReplicatedStorage")
remote.OnServerEvent:Connect(function(player)
player.Character:WaitForChild("Humanoid").Health = 100
end)
Local Script under StarterGui
local remote = game:GetService("ReplicatedStorage"):WaitForChild("HealthReload")
game:GetService("UserInputService").InputBegan:Connect(function(input, event)
if input.KeyCode == Enum.KeyCode.R then
remote:FireServer()
end
end)
1 comment
You would need to use a remote event to fill the humanoid’s health.