Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What is wrong with my random game teleporter?

Asked by 4 years ago

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

0
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. s_iara 94 — 4y
0
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. BrainDead_Dev 135 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.

0
where specifically should I put the math.random ACDCMASTA -1 — 4y
0
You decide that, put it anywhere above where it's needed. zboi082007 270 — 4y
Ad

Answer this question