Why won't my character spawn at the right area?

Are we sure it’s a code issue then? Maybe the SpawnLocations are not in the correct position?

1 Like

I am positive it is not that, I checked and rechecked all the positions, and names and such…

1 Like

Question regarding the following:

Does it print the “Park” or “Desert” prints?

1 Like

Park, every time, (except when the player first joins for some reason) and it will still spawn at the desert sometimes…

I returned to this screenshot, any reason why there are 4 spawns? Maybe only have 1 per area? Did you make sure ALL of the spawns under Desert are in the correct area & same for Park?

Also, if the goal is the pick a random spawn in the correct area, we can address that separately.

1 Like

@MRKYLO20 I may have the solution to your problems :slight_smile:

Been working on this in studio, and I got my version (minus testing with all the DataStore code) to work! The spawning has no problems.

So a few things to note:

  • Your MAIN issue is that when the Character is spawned, they are teleported so fast that they actually teleport before they are “spawned” on the SpawnLocation by ROBLOX’s default SpawnLocation code. So to fix this… drum roll please… add a wait() :wink:
  • You have 4 spawns (so I don’t know if you are wanting to have multiple spawns in each area that they randomly spawn on). So my code snippet allots for that kind of situation.

Okay so for the code:
Under the newCharacter(character) function:

wait()

if game.Workspace.Spawners:FindFirstChild(player:WaitForChild("PlayerPlace").Value) then
		
		print(player.PlayerPlace.Value) -- Location "Park" or "Desert" or etc.
		
		local AreaSpawns = workspace.Spawners:FindFirstChild(player.PlayerPlace.Value)
		
		if AreaSpawns ~= nil then
		
			-- pick random spawn from area list
			local randomSpawn = AreaSpawns:GetChildren()[math.random(1, #AreaSpawns:GetChildren())]
			character:SetPrimaryPartCFrame(CFrame.new(randomSpawn.Position.X, randomSpawn.Position.Y + 3, randomSpawn.Position.Z))
			
		end
		
	end

I also interpolated your PlayerPlace variable so that it checks the variable directly and uses it as a check instead of hard coding checks like

if player:WaitForChild("PlayerPlace").Value == "Park" then 
1 Like

Thank You! The random spawn thing works and so far it will spawn at the right part place, if I reset my character. except… when the player first joins, it spawns at the wrong place, and it won’t even print! I tried putting the wait for two seconds and it still didn’t do anything. The ISSUES I create! :rage: :thinking: :slightly_smiling_face:

1 Like

Weird, I went and tested again (just with bare-bones code – .PlayerAdded and .CharacterAdded with no DataStore), and it worked fine (even when the Player was added).

Bare in mind, I always deleted the code bit that was

so I’m not sure if that code does anything to the Player’s positioning or not.

Also, you can reinforce this testing by replacing all of the SpawnLocations with regular parts (of the same dimensions) and only include 1 or no SpawnLocations to see if it really places you or not because since all of the SpawnLocations are neutral, they will spawn you no matter the code, and it could spawn you on any of them no matter the “location” (Park / Desert) we have defined.

1 Like

Should I actually change the code to spawn at the parts instead of the locations or do you want me to just have the absence of any spawn, to see if they spawn at the locations at all in the first place?

1 Like

For proof, I changed the color of the spawns and made them visible, so I could see, and yup, it will do it on reset, but not on the first go. Also the main loop won’t mess up the position to my knowledge. So my best guess from all of this, since it won’t print, is something to do with it can’t catch the player to change the position in time. BUT… it does the rest of the code right after…

1 Like

This is just if you wanted to try to debug the code. I believe you are okay to leave them as SpawnLocations.

This is weird. At least the rest of the code works.

Does this line fire when you initially spawn in? (Even though it doesn’t place you unless you reset)

1 Like

Nope, that is what is SO strange!

My thoughts on this…
WHA?!?!?!?
:thinking: :no_mouth: :scream: :rage: :face_with_symbols_over_mouth: :face_with_raised_eyebrow:

How would you recommend I do this?

I figured out a solution for spawning the first time. I have a loading screen that blocks what happens so it is ok, whenever a player is touching a spawn but with a wrong value, they get sent to the right place. Kinda simple actually…