local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(input, processed)
if processed then return end
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.R then
local plr = game.Players.LocalPlayer
workspace.plr.Humanoid.Health = 0
end
end
end)
Dont Mind workspace.plr i tried WaitForChild too and it doesnt help
workspace.plr doesn’t quite work, as plr is not an instance in workspace. You will need to use plr.Character instead to appropriately and expectedly find the humanoid.
So i updated my code a little bit and still not working
local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(input, processed)
if processed then return end
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.R then
local player = game.Players.LocalPlayer
local character = player.Character
if not character or not character.Parent then
character = player.CharacterAdded:wait()
end
workspace:WaitForChild(character):FindFirstChild("Humanoid").Health = 0
end
end
end)
What i am doing Wrong and Thanks for telling me one of my problems
Hey there, I am personally not a experienced scripter but here is an example of a code I use for one of my games and it works perfectly.
local m = game.Players.LocalPlayer:GetMouse()
db = true
m.KeyDown:connect(function(r)
r = r:lower()
if r == "r" then
if db == true then
game.Players.LocalPlayer.Character:FindFirstChild("Humanoid").Health = 0
end
end
end)
This I keep under StarterPlayer > StarterCharacterScripts.
I don’t think you should be using UIS for resetting under no conditions, I’d recommend using ContextActionService, this is to avoid the same issue this guy had: