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

2 comments
not the most knowledgable in scripting, but it could be that the whole script is erroring because the random number of the 'game' might not exist. u could also place some print functions throughout the scripts, and see which goes through or just check the game's logs.
First of all, the script you gave would never teleport. The script is stuck in a while true do loop, constantly getting new place, but never teleporting. Secondly, for the touched event, you are not even checking if what touched the part even is descendant of a character. That would cause an error if something that is not part of a character touches it.