How do I make a player spawn inside a building

I’m trying to get the player to spawn inside a building but even though the spawn is inside the player still spawns on the roof. I have already tried turning off can collide on the roof but because it’s a union the can collide is all or none. After that I made the whole thing non-collide-able and made outer walls but it didn’t work very well so I came here. What can I do?

2 Likes

Spawns use a modified version of Model:MoveTo() and that function sucks, so I suggest placing Parts as “Spawns” and with the .CharacterAdded event set the CFrame of the character’s HumanoidRootPart to the spawn CFrame. You might as well randomize this with math.random.

2 Likes

Ok, I’ll assume that works but I have no idea how to script at all. How do I do that?

I will try a script. (Does not use math.random cuz mobile)
Meanwhile you can add a part with the name “BuildingSpawn” in Workspace and Anchor it, make it UnCanCollideable and Invisible, if wanted.

local part = workspace:FindFirstChild("BuildingSpawn")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
RunService.RenderStepped:Wait()
char.HumanoidRootPart.CFrame = part.CFrame
end)
end)

Additionally, this should be a Script in ServerScriptService.

2 Likes

Or you can make transparent SpawnLocation and set respawnlocation to it.

You can read more about it on DevHub: Here

game:GetService("Players").PlayerAdded:Connect(function(player)
player.RespawnLocation = workspace.spawn
end)

@octav20071

In your example I would rather use this:

game:GetService("Players").PlayerAdded:Connect(function(player)
task.wait()
player.Character:PivotTo(workspace.spawn:GetPivot())
end)

And btw you can’t use RenderStepped on server

2 Likes

Do they really? I tried putting a spawn inside of a small cube with no entries, and it works just fine.
Maybe it’s just that the ceilng in their house is too low for the player’s character?

Oh well, that hasn’t come in my mind.

From what I can say, it uses a

and I don’t know at all what tests you did.

For some reason this didn’t work.

Yes, .PlayerAdded events don’t work in Studio…
Might aswell be an error, what is it?

It says that RenderStepped can only be used from local scripts

Oh well, try .Stepped instead. Just delete “Render”.

1 Like

It works!

1 Like

I’d actually like to take a moment to say that the way I choose when making the script was the better one 'cause:
@caviarbro, RespawnLocation sets the respawn location next time the player dies, not when he joins. That wouldn’t be an option, here.


For the next option to do it, I was honestly impressed. But, the Pivot point changes if @xander5610 will ever change the location of the Part’s Pivot. By mistake, it happened to me. Thanks, everyone.

1 Like

That’s not a huge deal because you can just run player:LoadCharacter() under the line with setting respawnlocation