Hello everyone, I’m trying to make an automatic gate that opens only when a specific player touches it. I’m struggling with the script because I can’t understand what I’m doing wrong:
local team = game.Teams:WaitForChild("Police")
local idist = 11044391 -- group id of the team
local id = 7865740 -- group id for the admins
script.Parent.Regione.Touched:Connect(function(hit)
local human = hit.Parent:FindFirstChild("Humanoid")
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player and player.Team == team and player:GetRankInGroup(idist) >= 1 or player:GetRankInGroup(id) >= 254 then
print("it works")
end
end)
player.Team works fine but the issues are in player:GetRankInGroup(idist) >= 1 or player:GetRankInGroup(id) >= 254.
The problem may be related to the way your code “translates” the if statement. Try prioritizing the or check using brackets: ... and (player:GetRankInGroup(idist) >= 1 or player:GetRankInGroup(id) >= 254) then
This is probably the case, if writing print(player) one line above returns nil when the error occurs(because the part was touched by a random non-character part).