I’m making an obby and I need to change a players spawn point but every time I join it just puts my character at a random spawn point. If anybody could help with this that would be great.
For this, you wouldn’t use multiple spawn points. Make several “fake spawn points”. Each player has a stage right? When the player joins, they spawn on a normal spawn point (stage 0) Based on what stage they left off on, you can name the fake spawn points “1” or “2” or “3”. Then, loop through all of these spawn points and set the players CFrame to the corresponding spawn point + 0,5,0 (So they dont get stuck in it) I hope this is what you mean, sorry if I wasn’t clear about anything
example ( lemme thinking for early stuff i forget check first problem )
for i,v in pairs(workspace:GetChildren())do -- would be better if not workspace:GetChildren() should be add another folder then call something else workspace["Folder Name"]:GetChildren()
if v:IsA('SpawnLocation')then -- check if classname it's SpawnLocation else it won't going
v.Touched:Connect(function(hit)
if hit.Parent and game.Players:FindFirstChild(hit.Parent.Name)then -- verify it's a player
game.Players:FindFirstChild(hit.Parent.Name).RespawnLocation=v -- Player will respawn here forever until change, leave game or touching next spawnlocation
end
end)
end
end
This is pretty raw, so you’ll have to modify it to fit your needs.
local spawnPosition = Vector3.new(0, 10, 0)
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character:WaitForChild("HumanoidRootPart").CFrame = CFrame.new(spawnPosition)
end)
end)
Basically just moving the player to where you wish after spawn.
The strange thing is I’ve tried this and when I try to get the value of IntValue “Stage” in leaderstats, it returns as 0.
There only think you have add IntValue named “STAGE” for every “Spawn_stage” parts for then set some Value 1 for first spawn then Value 2 for second spawn
There no need SpawnLocation
game.Players.PlayerAdded:Connect(function(player)
local value=Instance.new('IntValue')
value.Name='STAGE'
value.Parent=player
value.Value=1
player.CharacterAdded:Connect(function(character)
for i,v in pairs(workspace:GetChildren())do
if v.Name=='Spawn_stage'and v.STAGE.Value==value.Value then
character:MoveTo(v.Position)
end
end
end)
end)
for i,v in pairs(workspace:GetChildren())do -- would be better if not workspace:GetChildren() should be add another folder then call something else workspace["Folder Name"]:GetChildren()
if v.Name=='Spawn_stage'then
v.Touched:Connect(function(hit)
if hit.Parent and game.Players:FindFirstChild(hit.Parent.Name)then -- verify it's a player
game.Players[hit.Parent.Name].STAGE.Value=v.STAGE.Value
end
end)
end
end