Trouble with random teleportation with TextButton

Hi there, hopefully I posted this in the right category…So what I am trying to achieve is making a textbutton that can teleport a player to a building but the problem is my game that I am developing is a single-player horror game, and you’re supposed to secure a single building(hotel), and its one player per hotel, and I’m not sure how to make a textbutton teleport the player to a different building without placing 2 people in the same building. So far I have tried this and it works, but it only teleports every player to the same point.

Use a local script, so it only teleport’s 1 player instead of everyone.

1 Like

It is a localscript, but how do I make it so that it checks the point to make sure there isn’t a already another player at that point? Here is what I have so far in my localscript, let me know where I can improve:

disabled = false

script.Parent.MouseButton1Click:connect(function()
	if disabled == false then
		disabled = true
		game.Workspace.Teleport.RemoteFunction:InvokeServer()
		wait(3)
		disabled = false
	end
end)

I’m thinking that you can make a table of the spawn points in the hotel. When a player is loaded into a certain spawn point, then you can take out the spawn point out of the spawn point table.

Also, the player would only spawn at a hotel if the spawn point is in the table. You can achieve this by looping through the spawn points through a for loop.

Hope this helps! :grinning:

2 Likes

Alright I will definitely attempt this, thank you for the advice!

You could create a main server-side table in a script, then when you teleport a player to one of the points, you take that point out of the table (or put it to the side). Then when someone else teleports, you cycle through the table with an “in pairs() do” loop, checking for which points are available. To check it in a localscript, you could use a remoteevent that sends the table over to the localscript, then checking it and sending a remoteevent back to the server to update the table.

1 Like

Thanks, I will try this although it was a bit similar to a table of spawn points as @dodle120 said.

Just use a folder instead of a table and search through the folder. I you want to be able to DISABLE the spawn points then just change the Enabled variable (if you are working with “SpawnLocation” or just put a BoolValue inside and name it: “Enabled” then you can change the value of that.

Hope that helps! :smile:

1 Like

Yes I will for sure try this out considering creating a table messed with debounce enabled = false with some other scripts