Attempt to index nil with 'WaitForChild'

Unless the value was made on the client.

It still wont work, the Touched event is only detected on the server so neither will work

Well what I mean is, if the hit event is ran on the client, then yes it will. Everything has to be entirely on the client of course.

I change the values from the server, via a regular script in server script service.
The value is also created on the server.

1 Like

The touched event can NOT run on the client, i did say that

Print its value and see what it gives.

It can if it’s in a local script.

1 Like

I printed it and it gave 255, my rank value.

1 Like

Which that was the point I was making, if it caused confusion.

Nope, i remeber touched events never run on the client (maybe was changed but most probably not)

1 Like

I’ve done it before. I’m more than sure, maybe I’m wrong but there is absolutely no reason why it wouldn’t work on the client.

1 Like

We’re going off topic…

Just to tell you, I tried this script in a local script at first and it didn’t work.
Touched events do not work on the client.

Yeah it won’t work in a local script if the value was made on the server.

1 Like

You cant use a touch event to run server commands if the touch event is on the client.

Just use this code

script.Parent.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if not player then return end
	if player:WaitForChild("GroupRank").Value < 250 then
		player.Character.Humanoid.ragdoll.Value = true
		player.Character.Humanoid.Health = 0
		game.ReplicatedStorage.Message:FireClient(player, "You shouldn't be in this room, it is for council members only!")
	end
end)
2 Likes

The error means that player is nil. Take the script you started with before all of the other advice and just check if player is nil. Also you’re making the wrong comparison, even when it doesn’t error currently it will only kill you above 250 health.

script.Parent.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if not player then return end -- new line to prevent the error.
	if player:WaitForChild("GroupRank").Value < 250 then -- You had >=, so it would only kill you above 250.
		player.Character.Humanoid.ragdoll.Value = true
		player.Character.Humanoid.Health = 0
		game.ReplicatedStorage.Message:FireClient(player, "You shouldn't be in this room, it is for council members only!")	
	end
end)

That should be all you need. Let me know if you have any other issues or errors.

Thank you! I didn’t realise that i had >= instead of <

I did change that in my code ;-;
All good ig lmao

1 Like

I cant make two answers the solution though

1 Like

@JarodOfOrbiter who should take it?
You can see i wrote before if u want it tho, you can have it

2 Likes