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

teleporting players to another game loop?

Asked by 4 years ago
Edited 4 years ago

I am trying to make a teleporter that teleports the players on it every 23 seconds but it doesn't work properly. It waits 23 seconds before teleporting for the first time but after it will teleport players all the time. Can somebody help me please? ( i am kinda new to scripting) This is my code:

01local TeleportService = game:GetService("TeleportService")
02local gameID = 6446611098 -- Game ID
03 
04while true do
05    wait(23)
06function onTouched(hit)
07    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
08    if player then
09            TeleportService:Teleport(gameID, player)
10 
11    end
12end
13 
14    script.Parent.Touched:connect(onTouched)
15    end

1 answer

Log in to vote
0
Answered by
sayer80 457 Moderation Voter
4 years ago

So the problem is the script first runs (wait 23 seconds) then the Function is active and listening and whenever a player touches the part they will get tped and the Function should also stack after each 23 seconds like it will try to teleport them to there 2 Times which is inefficient.

The Explanation is inside the code.

01local TeleportService = game:GetService("TeleportService")
02local gameID = 6446611098 -- Game ID
03local waitingtime = 23 -- time to wait
04local queue = {} -- stores player information
05 
06 
07 
08local function statushandler(player)
09    for _, queueplayer in pairs(queue) do
10        if queueplayer == player then
11            return end -- stops function when player is already in queue
12        end
13    table.insert(queue,player) -- add player to the queue
14end
15 
View all 36 lines...
0
Would appreciate if you accept when it helps sayer80 457 — 4y
1
thanks! you helped me! OctavianH0310 25 — 4y
1
actually, it stopped working now. it just doesnt teleport me anywhere OctavianH0310 25 — 4y
0
Are there any errors? sayer80 457 — 4y
0
When there is 1 error the loop can break forever sayer80 457 — 4y
Ad

Answer this question