#Attempt to index nil :(

12 messages · Page 1 of 1 (latest)

opal reef
#

i want to make an iftouched thats basically an "escape"

script:
**local CollectionService = game:GetService("CollectionService")
local teams = game:GetService("Teams")
local Player = game:GetService("Players")

script.Parent.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr.Team == game.Teams:WaitForChild("Prisoner") then
plr.Team = game.Teams:WaitForChild("Criminal")
elseif plr.Team.Name == "Criminal" then
CollectionService:AddTag(plr,"Guilty")
end
end)**

error:
Workspace.MapElements.Arrestability Thing.Script:8: attempt to index nil with 'Team' - Server - Script:8

help please!

arctic shadow
#
local CollectionService = game:GetService("CollectionService")
local teams = game:GetService("Teams")
local Player = game:GetService("Players")


script.Parent.Touched:Connect(function(hit)
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    if plr.Team == game.Teams:WaitForChild("Prisoner") then
       plr.Team = game.Teams:WaitForChild("Criminal")
    elseif plr.Team.Name == "Criminal" then
        CollectionService:AddTag(plr,"Guilty")
    end
end)```
#

plr is nil

#
local CollectionService = game:GetService("CollectionService")
local teams = game:GetService("Teams")
local Player = game:GetService("Players")


script.Parent.Touched:Connect(function(hit)
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    if not plr then return end
    if plr.Team == game.Teams:WaitForChild("Prisoner") then
       plr.Team = game.Teams:WaitForChild("Criminal")
    elseif plr.Team.Name == "Criminal" then
        CollectionService:AddTag(plr,"Guilty")
    end
end)```
opal reef
#

i have absolutely no freaking idea how that fixed it, and i would have never gotten that myself, but thanks for the fix!

#

also, this script is definetly quite ineffient at best lol, too bad!

mint sphinx
arctic shadow
opal reef
#

oh yeah, youre right

#

that makes total sense

#

i get it now

arctic shadow
#

Great, good luck with your game