Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is 'player' being indexed as a nil value?

Asked by 7 years ago

I want a player to be teleported away from a part if their team color doesn't match the part's color. Output says there is a problem with line 4, can anyone help me?

script.Parent.Touched:connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    wait()
    if player.TeamColor == BrickColor.new("Bright blue") or player.TeamColor == BrickColor.new("Really blue") and script.Parent.BrickColor == BrickColor.new("Bright green") then
        hit.Parent.Torso.CFrame = CFrame.new(Vector3.new(-49,4,109))
    elseif player.TeamColor == BrickColor.new("Bright green") or player.TeamColor == BrickColor.new("Camo") and script.Parent.BrickColor == BrickColor.new("Bright blue") then
        hit.Parent.Torso.CFrame = CFrame.new(Vector3.new(-49,4,-79))
    end
end)

0
The block is teleporting me no matter what team color I possess, which is the problem. User#4422 0 — 7y

2 answers

Log in to vote
1
Answered by 7 years ago

Try making "local player = " to "local player = game.Players.LocalPlayer" , add a wait(2) at line 1 and make it a local script

Ad
Log in to vote
1
Answered by 7 years ago
script.Parent.Touched:connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    wait()
    if player.TeamColor.BrickColor == BrickColor.new("Bright blue") or player.TeamColor.BrickColor == BrickColor.new("Really blue") and script.Parent.BrickColor == BrickColor.new("Bright green") then
        hit.Parent.Torso.CFrame = CFrame.new(Vector3.new(-49,4,109))
    elseif player.TeamColor.BrickColor == BrickColor.new("Bright green") or player.TeamColor.BrickColor == BrickColor.new("Camo") and script.Parent.BrickColor == BrickColor.new("Bright blue") then
        hit.Parent.Torso.CFrame = CFrame.new(Vector3.new(-49,4,-79))
    end
end)

Answer this question