Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is this spawning script not working correctly?

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

2 comments

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.

0

Try doing '~=' on the ifs.

1 answer

✓ Accepted answer

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 :)

2 comments

0

Thanks!

0

Your Welcome

This discussion is preserved as it was. New answers, comments, and votes are closed.