You know how in some sandboxes, when you spawn, you have your own spawn, and won't spawn anywhere else, and it doesn't show on the leaderboard, only stuff like KOs and WOs, or points will show.
I looked at this but I'm confused, it's not mine and I want to do my own. Could you explain it? And will it work?
function waitForChild(instance, name) while not instance:FindFirstChild(name) do instance.ChildAdded:wait() end end function waitForAnyChild(instance) while not instance:GetChildren()[1] do instance.ChildAdded:wait() end end print("ControlSpawning script", "waiting for children...") waitForChild(game.Workspace, "BuildingPlates") waitForChild(game, "Players") local debris = game:GetService("Debris") local assigning = false function getFirstAvailablePlayerNumber2(player) return 0 end function getFirstAvailablePlayerNumber(player) print("getFirstAvailablePlayerNumber()", "waiting...") -- wait for previous person to be assigned while(assigning) do assigning.Changed:wait() end assigning = true local playerNumber = 1 local numberOfBaseplates = #game.Workspace.BuildingPlates:GetChildren() local players = game.Players:GetChildren() local numberOfPlayers = #players print("getFirstAvailablePlayerNumber()", "numberOfBaseplates:", numberOfBaseplates, "numberOfPlayers:", numberOfPlayers) for i=1,numberOfBaseplates do local isTaken = false for j=1,numberOfPlayers do if(players[j]:FindFirstChild("playerNumber") ~= nil) then if(players[j].playerNumber.Value == i) then isTaken = true end end end if(isTaken == false) then -- We've found the first (lowest) available number playerNumber = i print("getFirstAvailablePlayerNumber()", "numberOfBaseplates:", numberOfBaseplates, "numberOfPlayers:", numberOfPlayers, "playerNumber:", playerNumber) assigning = false return playerNumber end end -- Shouldn't get here print("All baseplates are full. That shouldn't happen.") assigning = false return 0 end function onPlayerRespawn(player) -- only interested in events where the player gets a new character if player.Character == nil then return end print("onPlayerRespawn()", player.Name, "getting playerNumber...") if player:FindFirstChild("playerNumber") == nil then playerNumber = Instance.new("IntValue") playerNumber.Name = "playerNumber" playerNumber.Value = getFirstAvailablePlayerNumber(player) playerNumber.Parent = player end print("onPlayerRespawn()", player.Name, "playerNumber:", player.playerNumber.Value, "yielding...") wait() local char = player.Character.Torso local placeToSpawnTo = game.Workspace.SpawnPoints:FindFirstChild("SpawnLocation"..tostring(player.playerNumber.Value)) if placeToSpawnTo ~= nil then print("onPlayerRespawn()", player.Name, "playerNumber:", player.playerNumber.Value, "placeToSpawnTo:", placeToSpawnTo.Name) -- set Y position 3 studs above spawn position (otherwise player's torso is stuck in ground) char.CFrame = CFrame.new( placeToSpawnTo.Position + Vector3.new(0,3,0) ) else -- Couldn't find spawn location with that name. -- So, spawn in the normal spawn location (outside the plates) -- Extra players without baseplates are given playerNumber 0, and they spawn here. print("Spawning", player.Name, ", playerNumber:", player.playerNumber.Value, "in neutral spawner.") end -- Remove the forcefield because it's ugly. waitForChild(player.Character, "ForceField") --forceField:Remove() -- draw fancy crap local fire1 = Instance.new("Fire") fire1.Color = Color3.new(1, 1, 1) fire1.SecondaryColor = Color3.new(0, 0, 1) fire1.Heat = 20 fire1.Size = 10 fire1.Parent = placeToSpawnTo --debris:AddItem(fire1, 5.00) local fire2 = Instance.new("Fire") fire2.Color = Color3.new(0.02, 0.02, 0.1) fire2.SecondaryColor = Color3.new(0.1, 0.1, 0.10) fire2.Heat = 0 fire2.Size = 2.5 fire2.Parent = player.Character.Torso --debris:AddItem(fire2, 10.00) wait(0.2) fire1.Size = 8 wait(0.2) fire1.Color = Color3.new(.8, .8, .8) fire1.Size = 5 wait(0.2) fire1.Size = 3 wait(0.2) fire1.Enabled = false; wait(2) fire2.Enabled = false; print("Fire created") end function onPlayerEntered(newPlayer) -- start to listen for new humanoid newPlayer.Changed:connect(function(property) onPlayerPropChanged(property, newPlayer) end ) onPlayerRespawn(newPlayer) end function onPlayerPropChanged(property, player) if property == "Character" then onPlayerRespawn(player) end end game.Players.ChildAdded:connect(onPlayerEntered) print("ControlSpawning script", "Players.ChildAdded event has been added.") -- In Play Solo mode, the event doesn't fire. So, we have to manually fire it. -- Wait for Player print("Waiting for any child in game.Players...") waitForAnyChild(game.Players) local players = game.Players:GetChildren() if(players[1]:FindFirstChild("playerNumber") == nil) then print("Manually adding playerNumber") onPlayerEntered(players[1]) else print("Player already has playerNumber.") end
Thanks.