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

How would i fix my game Tag Script?

Asked by 10 years ago
function Choose()
    local players = game.Players:GetChildren()
    local RandomPlayer = players[math.random(1, #players)]
    game.Workspace.IT.Value = RandomPlayer.Name
    wait(3)
    local weld = Instance.new("Weld")
    local Player = game.Workspace:WaitForChild(RandomPlayer.Name)
    local Torso = Player:WaitForChild("Torso")
    Scr = game.Workspace.Tag:Clone()
    weld.Parent = Scr
    weld.Part0 = Torso
    weld.Part1 = Scr
    Scr.Parent = Torso
    Scr.CFrame =CFrame.new(Torso.CFrame.X,Torso.CFrame.Y,Torso.CFrame.Z)


end

while game.Workspace.Play.Value == false do
    local Pl = game.Workspace:FindFirstChild(game.Workspace.IT.Value)
    local Torso = Pl:WaitForChild("Torso")
    game.Workspace.Play.Value = true
    wait(3)
    Choose()




    wait(20)
    Torso.Tag:Remove()
    game.Workspace.IT.Value = ""
    game.Workspace.Play.Value = false





end

Output


I have arrived. Waiting for ... CoreScripts/BackpackScripts/BackpackManager BackpackOpenEvent Waiting for ... CoreScripts/BackpackScripts/BackpackManager BackpackCloseEvent Waiting for ... CoreScripts/BackpackScripts/BackpackManager TabClickedEvent Waiting for ... CoreScripts/BackpackScripts/BackpackManager SearchRequestedEvent Waiting for ... CoreScripts/BackpackScripts/BackpackManager BackpackReady Waiting for ... CoreScripts/BackpackScripts/BackpackManager BackpackReady 18:10:44.088 - Auto-Saving... 18:10:44.514 - Unable to load plugin icon. Image may have an invalid or unknown format. 18:10:44.524 - Unable to load plugin icon. Image may have an invalid or unknown format. 18:10:45.661 - Workspace.Brain:26: attempt to index local 'Pl' (a nil value) 18:10:45.662 - Script 'Workspace.Brain', Line 26 18:10:45.662 - stack end logging probability 0.3267616809595 not logging Alerted Gui Maker Plugin loaded 18:11:21.563 - Auto-Saving...

This is my current code as follows please offer suggestions... basicly what im trying to do is have a loop that only runs when i want to and when the loop is true it fires the function that chooses the player

0
What is the problem with it? User#2 0 — 10y

2 answers

Log in to vote
0
Answered by 10 years ago

What is output?

0
ill copy link Chaserox 62 — 10y
Ad
Log in to vote
0
Answered by
Tkdriverx 514 Moderation Voter
10 years ago
function Choose()
    local players = game.Players:GetChildren()
    local RandomPlayer = players[math.random(1, #players)]
    game.Workspace.IT.Value = RandomPlayer.Name
    wait(3)
    local weld = Instance.new("Weld")
    local Player = game.Workspace:WaitForChild(RandomPlayer.Name)
    local Torso = Player:WaitForChild("Torso")
    Scr = game.Workspace.Tag:Clone()
    weld.Parent = Scr
    weld.Part0 = Torso
    weld.Part1 = Scr
    Scr.Parent = Torso
    Scr.CFrame =CFrame.new(Torso.CFrame.X,Torso.CFrame.Y,Torso.CFrame.Z)
end

while game.Workspace.Play.Value == false do
    local Pl = game.Workspace:FindFirstChild(game.Workspace.IT.Value)
    if Pl then
        local Torso = Pl:WaitForChild("Torso")
        game.Workspace.Play.Value = true
        wait(3)
        Choose()
        wait(20)
        Torso.Tag:Remove()
        game.Workspace.IT.Value = ""
        game.Workspace.Play.Value = false
    else
        print("NO IT")
    end
end

The error was probably because Pl was nil. You tried to call a method of something that doesn't even exist. So, you need to have the code check if Pl exists, and if it does, continue.

Answer this question