I need a little help with a script, so this script is under a brick titled “RespawnPart”
what it is suppose to do is if a player is in the group it makes the part can collide off if the player isnt in the group then it respawn them, it doesnt seem to work is there anyone who can help me out?
here is the script
script.Parent.Touched:connect(function(hit)
game.Players.PlayerAdded:Connect(function(Player)
if Player:GetRankInGroup(5935088) == 4 then
script.Parent.CanCollide = false
else
if hit.Parent:findFirstChild("Humanoid") and debounce == false then
debounce = true
game.Players:GetPlayerFromCharacter(hit.Parent):LoadCharacter()
end
wait(0.5)
debounce = false
end
end)
You want to find the player from the hit and then determine if they should pass or not. A playeradded function inside of a touched event doesn’t make sense as the player is already in the game! Try this. If you instead wanted to not kill the player but have them stuck at the brick, you could set a collision group for the player that is allowed access, so they can collide with the part and walkthrough, whereas the other player could not. You can check out that api here: https://developer.roblox.com/en-us/articles/Collision-Filtering
script.Parent.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if Player:GetRankInGroup(5935088) == 4 then
script.Parent.CanCollide = false
wait(2)
script.Parent.CanCollide = true
else
debounce = true
hit.Parent.Humanoid.Health = 0
game.Players:GetPlayerFromCharacter(hit.Parent):LoadCharacter()
end
wait(0.5)
debounce = false
end
end)
Let me know if you need any more help. Cheers and good luck!
It respawns me when im in the group
This is likely happening because you have it set to allow only rank 4 inside. If you want rank 4 or higher, use this code:
script.Parent.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if Player:GetRankInGroup(5935088) => 4 then
script.Parent.CanCollide = false
wait(2)
script.Parent.CanCollide = true
else
debounce = true
hit.Parent.Humanoid.Health = 0
game.Players:GetPlayerFromCharacter(hit.Parent):LoadCharacter()
end
wait(0.5)
debounce = false
end
end)
Notice the difference between ==
(equal to) and =>
(equal to or greater than)
Wasn’t working but i changed to > 3 (greater than 3) and it works fine, thanks for the help im going to mark his as solution as he made the base script but thanks for the help 
1 Like