Whenever I click the button that teleports the target player in the game, it doesn’t teleport the player to each of the games. It is supposed to do that, but it is refusing to. I do not know how it isn’t functioning to do that.
This is all wrong, so i’m just going to post the issues in bullet points:
-
Don’t use screenshots to show your code – we have codeblocks for this reason and it allows you and other people to copy your code easily
-
You shouldn’t really nest connections because when the first event fires, it’s going to create new listeners for the connections that are nested, thus causing the function(s) connected to the event to be ran several times. Nested connections can also cause memory leaks since connections are objects and they take up memory
-
Even if the connections are nested, which they aren’t supposed to be as mentioned above, you aren’t putting the ends for each of them and only doing it for one – this will cause syntax errors
With that, you can make it actually choose a random place and teleport the player to it using a table holding the random IDs and math.random
. Math.random returns a number between two integers if passed as arguments. Here’s what you can use;
local IDs = {
-- game ID here
-- another game ID here (if necessary)
-- ... (etc.)
}
local TS = game:GetService("TeleportService")
script.Parent.MouseButton1Click:Connect(function()
local randomPlace = IDs[math.random(1, #IDs)]
TS:Teleport(randomPlace)
end)
Thank you for the info, I did realize that all the ID’s had to go in brackets.