When the player joins the game, the character is supposed to spawn to a specific spawn according to their player number and the spawn name. For some reason it doesn't work. Can someone help?
(Script is inside a normal script in ServerScriptStorage
)
game.Players.PlayerAdded:Connect(function(player) local playernum = Instance.new("StringValue") playernum.Parent = player playernum.Name = "Player" local players = game.Players:GetPlayers() --Gets how many players there are when a player joins the game for _, v in pairs(players) do playernum.Value = "Player"..#players --The value is how ever many players there are end player.CharacterAdded:Connect(function(char) local humanoid = char:WaitForChild("Humanoid") local spawnlocations = game.Workspace:WaitForChild("BloxopolyBoard"):WaitForChild("SpawnLocations"):GetChildren() --Gets all the children in the spawn locations local spawnfolder = workspace:WaitForChild("BloxopolyBoard"):WaitForChild("SpawnLocations") if humanoid then --If the humanoid exists for i, v in pairs(spawnlocations) do if playernum.Value == v.Name then --If the player's number matches the name of one of the spawn locations print(playernum.Value) --Indicator to see if it is working up until this point local torso = humanoid.Parent:FindFirstChild("Torso") torso.CFrame = CFrame.new(spawnfolder:FindFirstChild(playernum.Value).Position) + Vector3.new(0, 3, 0) --Find one of the spawn locations in the spawn folder that matches the player's number and spawn them to that part (This part doesn't work) end end end end) end)
It just stops working up until the print(), but I get no errors.
It month be that playernum
Is a StringValue
instead of aIntValue