Help with changing players health

im trying to make it so if a player enters a passcode incorrectly they get shot. this is the script

location: inside local scritpt inside gui

	if script.Parent.Parent.TextBox.Text == "v" then
		script.Parent.Parent.Parent.Error.Text = "Password Accepted. Welcome"
		script.Parent.Parent.Parent.Error.TextColor3 =, 1, 0.14902)
	else script.Parent.Parent.TextBox.Text = " "
		script.Parent.Parent.Parent.Error.TextColor3 =, 0, 0.0156863)
		script.Parent.Parent.Parent.Error.Text = "Incorrect Password. Access Denied"
		script.Parent.Parent.Parent.Error.Text = " "
		script.Parent.Parent.Parent.Error.Text = "Incorrect Password. Access Denied"

		local ui = script.Parent.Parent.Parent.Parent.Die
		local menu = script.Parent.Parent.Parent.Parent.Menu


		local player = game:GetService("Players")
		local humanoid = player:WaitForChild("Humanoid")

		humanoid.Health = 0

		ui.Visible = true
		local Death2 = plr:WaitForChild('PlayerGui'):WaitForChild("ScreenGui"):WaitForChild("Death2")
		Death2.Visible = true
		ui.Visible = false

		plr:Kick("You Died")

		print("everything good")

error: not able to change players health through local script.

Changes to the health property of a Humanoid instance will not replicate to the server if done from the client, you’ll need to use a RemoteEvent to fire the server and then in some server script perform the health deduction.

1 Like

this is not correct. the humanoid is inside the player character.

add ‘.LocalPlayer’ to that.
If you really wanna do it from the client, destroy the player’s head. That replicates to the server. if you want to kill the player via a local script do this:

local player = game:GetService('Players').LocalPlayer
local character = player.Character
local head = character:FindFirstChild('Head')
head:Destroy() --death by beheading, funny

Or do what Forummer said, which is a lot more practical.

1 Like

does this have to be a script or a local script cause I am having this issue to

Okay so basically you need to understand client vs server

Client: The individual player (local script)
Server: All players (script)


refers to the individual player. Since the server is all players and not individual players it doesnt know what the individual player is. You can tell it what player to affect by saying


If you do want to use Game.Players.LocalPlayer you would have to do it on the client. (remember the client is a local script) This is because, since the client is every individual player, it knows what you are talking about. The game clones the local script to every player that joins, so every player that joins has a different local script with data thats important to them specifically. (like their player properties)

The reason I see in my code why I wasn’t able to change the players health was because I was trying to say Player.Health which health is not a property of player. Instead what I should have done is say


Saying game.Players.LocalPlayer gets the player model inside of the players tab

But saying game.Players.LocalPlayer.Character gives me the players character which is located inside of workspace

The humanoid is a child of the players character inside of workspace so you have to reference Player.Character then you say
Health is indeed a property of every humanoid

so you say for local scritps:

game.Players.LocalPlayer.Character.Humanoid.Health = (Any amount)

and for scripts

game.Players.(playername).Character.Humanoid.Health = (Any amount)
1 Like

@Ma7adi805 Tell me if this helps. Sorry for being rude earlier, I thought you were someone who was responding to my post in terms of trying to help me, not get help.

Uploading: image.png(1)…

that is the error I am getting from the script you gave me and it is local script

Looks Like The image is not uploading so I will be saying it by text

20:29:30 -- Humanoid is not a valid member of Model "Workspace.Ma7adi805"
            Stack Being
            Script 'Players.Ma7adi805.PlayerGui.Settings.Settings2.confirmication.Yes.LocalScript', Line 6

that means the humanoid doesnt exist because the game hasnt loaded yet. Put a wait() or something