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

In this script im getting a error that doesn't let me respawn player and change team. ?

Asked by
Vxyrion 23
6 years ago
Edited 6 years ago

Error: "attemping to index local 'player' (a nil value) "

local debounce = true


script.Parent.Touched:Connect(function(hit)
    if debounce == true then 
        print("debounce is turning off")
        debounce = false
        local player = game.Players:GetPlayerFromCharacter(hit.Parent) -
        for i,v in pairs(game.Players:GetPlayers()) do with a for loop
            if v.Name == player.Name then 
                print("Found player "..v.Name)
                if v.TeamColor ~= BrickColor.new("Really red") then 
                    print("Not in this team")
                    v:LoadCharacter()
                    debounce = true
                else 
                    print("You are on this team")
                    debounce = true
                end
            end
        end
    end
end)

0
Why is there a dash on line 8 and why is there 'do with a for loop' on line 9 LifeInDevelopment 364 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

What was the point of using a for loop with :GetPlayers() to check if the player who touched was in the game when you already got the player by using :GetPlayerFromCharacter ?

local Team = game.Teams.Raider --put team name here
local Debounce = false
script.Parent.Touched:Connect(function(hit)
    if Debounce == false then
    Debounce = true
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        if player.Team ==  Team then
            print(player.Name.." is already on Team "..Team.Name)
        else
            player.Team = Team
            print(player.Name.." is now on Team "..Team.Name)
            end
end
wait(3)
Debounce = false
end
end)

Please accept my answer if this helped!

0
^A,lright so, I spotted a error on line 7 "=" needed to be changed to "==" Also, I'm still getting the same error. Vxyrion 23 — 6y
0
Updated my answer. Tested this so it will work. PyccknnXakep 1225 — 6y
Ad

Answer this question