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.
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.
I printed it and it gave 255, my rank value.
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)
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.
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.
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)
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
I cant make two answers the solution though
@JarodOfOrbiter who should take it?
You can see i wrote before if u want it tho, you can have it