What do you want to achieve? Keep it simple and clear!
I created an invisible wall in which when players who touch it do not belong the “Visitors” Team, they can pass through.
What is the issue? Include screenshots / videos if possible!
It throws the error “Attempted to index nil with ‘Team’”.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried looking for solutions around devforum but so far haven’t found any working ones.
The code is placed inside a part.
script.Parent.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr.Team.Name ~= "Visitors" then
script.Parent.CanCollide = false
script.Parent.TouchEnded:Wait()
script.Parent.CanCollide = true
end
end)
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
if plr.Team.Name ~= "Visitors" then
script.Parent.CanCollide = false
task.wait(3)
script.Parent.CanCollide = true
end
end
end
end)
The problem with TouchEnded is, that even if you’re no longer touching the brick ,but still on it, even with your feet, it’d run the code, which we dont want to happen.
You could also add a debounce if you want to create a delay and stuff.