Custom spawn script not working?

so i made this script
image
which should spawn players at custom spawn points, but for some reason i always spawn at 0,0,0
image
however, if i do this instead:
image
it suddenly works. why is that?

2 Likes

Did you disabled CharacterAutoLoad in Players Service?
Otherwise, the player will be spawned at 0,0,0, and its not in sync with the SetPrimaryPartCFrame change you are doing. It could happen before or after you changed the CFrame, so the character will spawn at 0,0,0

The reason why works with the second code, its because, you are retrying 100 times, so, after the AutoLoad did happen at 0,0,0, your script is maybe on the retry 10 repeat, and in the next one “teleports” the player to the desired spawn point again.

You could disable the AutoLoad, and handle it with your script by using LoadCharacter()

I need the formatted version of the script and roblox doesn’t want you to use pictures for scripts, you should put three backticks (```)

also you’re using deprecated code, wait() should be replaced with task.wait() as it’s more accurate, model:SetPrimaryPartCFrame() should be replaced with PVInstance:PivotTo()

i just did that and it still didnt work

local spawns = workspace.Spawns
local TS = game:GetService("TweenService")

game.Players.PlayerAdded:Connect(function(plr)
	plr:LoadCharacter()
	plr.CharacterAppearanceLoaded:Connect(function(char)
		for i,v in pairs(spawns:GetChildren()) do
			if v.Taken.Value == false then
				task.wait()
				char:SetPrimaryPartCFrame(v.SpawnPos.CFrame)
				v.Taken.Value = true
				break
			end
		end
	end)
end)

for i,v in pairs(spawns:GetChildren()) do
	TS:Create(v.Floor,TweenInfo.new(30),{Transparency=1}):Play()
end

wait(30)

workspace.Started.Value = true

for i,v in pairs(spawns:GetChildren()) do
	v.Floor:Destroy()
end

for i,v in pairs(game.Players:GetChildren()) do
	v.Character.HumanoidRootPart.Anchored = false
end

ive tried using pivotto and it still didnt work.

Nope, you need to connect the functions that will occur when the event fires before triggering the event, otherwise, you would be firing the event before the connections are placed. Like pouring the water before putting the glass.

Make sure you wait for the existance of the stuff you are referencing by using WaitForChild(). And take in count if none spawns points still available, players will spawn at 0,0,0

local spawns = game.Workspace:WaitForChild("Spawns")

game.Players.PlayerAdded:Connect(function(plr)
	
	-- Connect an event
	plr.CharacterAppearanceLoaded:Connect(function(char)
		for i,v in pairs(spawns:GetChildren()) do
			if v:WaitForChild("Taken").Value == false then
				v.Taken.Value = true
				warn(plr, "will spawn at:", v.Name)
				game:GetService("RunService").Stepped:Wait() -- A little wait
				char:SetPrimaryPartCFrame(v:WaitForChild("SpawnPos").CFrame)
                break
			end
		end
	end)
	
	-- Finally load the character after performing connections etc.
	plr:LoadCharacter()
end)
1 Like

yeah that works just fine. thanks!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.