Update: Roblox has seem to of fixed it now. Thanks for everyone that was trying to help
Hello. I made a teleporting script when its out of the function it works fine but when I have it in a function it doesn’t work
Update: Roblox has seem to of fixed it now. Thanks for everyone that was trying to help
Hello. I made a teleporting script when its out of the function it works fine but when I have it in a function it doesn’t work
I don’t see any reason right now that this code wouldn’t work. Are you getting any errors? Could you add some print statements to track the execution of the code - make sure theres one just inside the LiveEvent
function and another within the for loop.
Edit: Also, is this code located in a LocalScript or Script?
I think this code should work but this could not work because it is inside a different script type. By types of script I mean Local script, script module script and so on
What calls LiveEvent to run? Are you sure LiveEvent is actually running? Use a print statement inside the function and see if the game prints when you’d expect it to.
One possible solution is that the function is called before the player joins the server. Please use print statements to debug it and come back to us.
Server script service normal script when I have it in a function it doesn’t work but when its out of it it works fine
It works out of the function but not in it
Its in a normal script and works fine when its out of the function but when its in it it won’t work never worked when I tried in the live event thing so I took it out of there and turned that into a comment and tried calling it out of it
It worked fine out the function but doesn’t seem to work in it.
But I’ll still try it
I mean teleporting to another game
I am dumb I did not check the script again so if thats the case try
local TeleportService = game:GetService(“TeleportService”) local placeID_1 = 408502340 local placeID_2 = 408502380 local function onPartTouch(otherPart) local player = game.Players:GetPlayerFromCharacter(otherPart.Parent) if player then TeleportService:Teleport(placeID_1, player) end end script.Parent.Touched:Connect(onPartTouch)
Something like this
Is it possible that the wait(3) at the bottom of the script just doesn’t give the player enough time to load in? Try changing the wait to IO seconds. Also maybe add prints inside of the loop to see I it makes it to that part.
I’ll look into it. I might report this to Roblox if I have too
I’ve tried waiting 1 minute [wait(60)] still didn’t work. When I used the command bar in normal game with 2players it worked so I have no idea what its doing
When I copied and pasted this into the command bar when playing the game it worked fine but a script says NO THANK YOU!
I’ll email Roblox and ask if they can help. I could try a module script and putting it in the while loop instead of a function
I think the problem here is that you are using “pairs” rather than “ipairs”
pairs are used in dictionaries such as
{Apple = 1, Banana = 2, ["Coconut"] = 3}
whereas ipairs are used in arrays like
{"Bruh", "lol", "nice bro"}
Consider switching to
for i,v in ipairs(game.Players:GetPlayers()) do
and see if that solves the problem?
I’ve tried ipairs too and it works fine out of the function anyways I’ve even tried doing a table so game.Players.PlayerAdded… table.Insert(Players, game.Players.LocalPlayer) bla bla
If you’re trying to teleport players after a certain number of time, you could probably set a wait and then loop through the current players, as well as calling the teleport function when the player joins.
local Players = game:GetService("Players")
local TeleportService = game:GetService("TeleportService")
wait(30) -- WAIT TIME BEFORE LIVE EVENT
for _, player in ipairs(Players:GetPlayers()) do
TeleportService:Teleport(5749359923, player)
end
Players.PlayerAdded:Connect(function(player)
TeleportService:Teleport(5749359923, player)
end)
Also, make sure you have the code within a server script in ServerScriptService like this
Pairs can be used for Dictionaries or Tables, the only difference is that ipairs will guarantee that i is an integer.