I am trying to make a random game teleporter, (much of the code is from an Eppobot video, but I modified it for my needs) and I ran into the issue initially when I used math.random(100000000, 999999999) for the place ID, but then I realised it didn't reset or change. (It did work) the ID that it generated stayed the same on the server until it closed, which is damaging because it tries to teleport to a restricted place repetitively sometimes. So I made an infinite loop with a variable that was given a new math.random every second, and then I made the place ID equal to the variable, but now it doesn't teleport at all. here is my code:
while true do randomgame = math.random(100000000,999999999) wait(1) end local TeleportService = game:GetService("TeleportService") local Place = randomgame script.Parent.Touched:connect(function(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player then TeleportService:Teleport(Place, player) end end)
Thank you for taking the time to look at this. Sincerely, ACDCMASTA
Your while loop causes an infinite yield. Put the math.random in your .Touched event so it's a random number every time someone touches it, I also recommend a debounce for performance reasons.