Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to teleport a player to an open seat when they join the game?

I pretty basic at scripting, so this is my code~~~~~~~~~~~~~~~~~

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local seats = workspace.inside.Folder:GetChildren()
		local randomseat = math.random(#seats)
		local selectedseat = seats[randomseat]
		char.Torso:MoveTo(seats.Position)
	end)
end)
I really don't have an idea of what to do. Also do i needs the actual "seat" interaction tool or can it just be parts? Thanks in advance

1 answer

Well... Lets try it

If you want you can also just use normal Parts.

First Step : First of all we need to know how many seats we have on our folder. I recommend to put the name like this, if is the sit one then put on the name "1". So the math.random() will be easier for you.

Second Step : Second, we need to know where's the player right now. And teleport it to the part or the seat. So we will use a Vector3.new function

Third Step : After completing all the steps before this one, only sit on your seat and enjoy your code.

Lets go to the code!

--[[
	We can also add a Part where the Players will spawn, so if they touched we will get the 
	character and use the Vector3.new easy.
	But I'll make it like you want it.
]]

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)

	local randomseat = math.random(1, 6) --> Change it to your seat number
	local seat = workspace.inside.folder:WatiForChild(randomseat)
	
	--> Edit

	local humanoid = character:WaitForChild("Humanoid")
	humanoid.HumanoidRootPart.CFrame = CFrame.new(seat.Position)
	end)
end)

And that's all we need! Let me know if this solve your question!

Edit : I only change two lines of code. [9-10]

Keep scripting!

6 comments

1

why not usijng math.random(1, #seats) ?

0

It is telling me that vector3 is not a valid member of model?

0

Let me edit it again with CFrame.

0

Try it now @AdministrativeFellow

0

@Foxy_Developer its telling the same error except CFrame: CFrame is not a valid member of Model. Is this caused because my chair is just a giant union?

0

@AdministrativeFellow, try it now.

This discussion is preserved as it was. New answers, comments, and votes are closed.