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

Why is this spawning script not working correctly?

Asked by 8 years ago

This spawning script is supposed to detect if a value in a player is false and if a value in Workspace is true. If that is the case, the script is supposed to teleport the player if and only if that is the case.

However, even if the value in Workspace is false, the script still teleports players. I have no idea why it is doing this, as output didn't give me anything.

Can someone please help me? Here's the script:

local Player = script.Parent.Parent
local Started = game.Workspace:WaitForChild("Go")

while wait(0.1) do
    if Started.Value == true then
        if Player.PlayerGui.Teleported.Value == false then
            Player.PlayerGui.Teleported.Value = true
            local torso = Player.Character.Torso
            local spawns = {}
            if Player.TeamColor == BrickColor.new("Bright blue") then
                for i,v in ipairs(game.Workspace.Map.Humans:GetChildren()) do
                    if v.Name == "Spawn" then
                        table.insert(spawns,v)
                    end
                end
                if Player.Lethals ~= nil then
                    local children = Player.Lethals:GetChildren()
                    for i = 1, #children do
                        children[i].Value = 2
                    end
                end
                torso.CFrame = spawns[math.random(1,#spawns)].CFrame + Vector3.new(0,4,0)
            elseif Player.TeamColor == BrickColor.new("Bright red") then
                for i,v in ipairs(game.Workspace.Map.Zombies:GetChildren()) do
                    if v.Name == "Spawn" then
                        table.insert(spawns,v)
                    end
                end
                if Player.Lethals ~= nil then
                    local children = Player.Lethals:GetChildren()
                    for i = 1, #children do
                        children[i].Value = 2
                    end
                end
                torso.CFrame = spawns[math.random(1,#spawns)].CFrame + Vector3.new(0,4,0)   
            end
        end
    end
end
0
To check if something exists or not, you *have* to use :findFirstChild() -- where you have Player.Lethals. Also try using pairs instead of ipairs. Another thing: Use SpawnLocations. They will work the same way. Tkdriverx 514 — 8y
0
Try doing '~=' on the ifs. TheDeadlyPanther 2460 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

This is a simpler way to do it, [This is how my game does it]

for i, v in pairs(game.Players:GetPlayers()) do 
    if v.TeamColor == BrickColor.Blue() then 
        local bluespawns = game.Workspace:FindFirstChild("TTBlueSpawns"):GetChildren() 
        v.Character:MoveTo(bluespawns[i].Position)
    elseif v.TeamColor == BrickColor.Red() then 
        local redspawns = game.Workspace:FindFirstChild("TTRedSpawns"):GetChildren() 
        v.Character:MoveTo(redspawns[i].Position) 
    end
end

What goes on here is that I have a model in the workspace grouped with a bunch of random bricks everywhere. Which for certain team colors they go to separate models (With separate spawns)

I hope you can somehow work this into your script :)

0
Thanks! CoolJohnnyboy 121 — 8y
0
Your Welcome CarterTheHippo 120 — 8y
Ad

Answer this question