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

wait(10) won't work, skips to next command in script?

Asked by
mewtify 26
4 years ago

hello, I am trying to make a local script run at a certain time for all players (this is a reserved server, and a specific group of players are being teleport in) my goal with this was to have all the players in a block like structure, and the "ground" of the box will cancollide off which will let the players fall into the main game which will have a detector that will broadcast an event to start the script when touched. I am aware this is not the best solution, but after researching this is the only thing I can come up with.

this doesn't work for some reason because the floor automatically lets the players fall through, even though I set it as cancollide on. I tried deleting the script and then the ground of my structure was fine, and players weren't able to fall through, so I came to the conclusion that the wait(10) wasn't working for some reason.

here is my code, "down" is the ground that should hold the players and then turn cancollide off which lets them fall through.

wait(10)
workspace.down.CanCollide = false

I doubt anything I said made sense, but basically the wait(10) won't wait. I tried searching up help but nothing matching my problem helped. thanks for the help!

0
The script starts as soon as the server starts, so it can be because you take some time to join the server. Try making it wait for a player to join, THEN waiting 10 R_LabradorRetriever 198 — 4y
0
I added Instance:WaitForChild() before the script and now the wait(10) won't work and I now the "down" never does CanCollide = false for some reason, I am not very well at coding so if I didn't do it right please correct me :) mewtify 26 — 4y

2 answers

Log in to vote
0
Answered by
lunatic5 409 Moderation Voter
4 years ago

Maybe try something like the following to ensure the player has been added:

game:GetService("Players").PlayerAdded:Connect(function()
    wait(10)
    workspace.down.CanCollide = false
end)

This, however, will fire every time a new player joins the server. If you want it to happen only when the server starts (or when the first player joins), write the following instead:

local players = game:GetService("Players")

players.PlayerAdded:Connect(function()
    if #players:GetPlayers() == 1 then
        wait(10)
        workspace.down.CanCollide = false
    end
end)

Hope this helps.

0
Thanks for the help, the second code worked for me, but the script only waits for about half a second. I think it may be my computer, but my friend helping to make the game said they are having the same problem too. Should I make the wait to around 30 seconds so it will wait hopefully longer or will that somehow mess with one or all the players? mewtify 26 — 4y
0
Are you testing in Studio or in the game itself? I feel like that could play a role as Studio is usually slower. You shouldn't have to change it to 30 seconds though because that would just make it inconsistent. lunatic5 409 — 4y
0
What does #player mean iivSnooxy 248 — 3y
Ad
Log in to vote
-1
Answered by 4 years ago

i think you need to put some coding before the "wait (10)" bit perhaps plus also some other things

workspace.down (function()
wait (10) then
workspace.down.CanCollide = false

if that does not work then i will message you next time when i know the answer

0
this didn't seem to work, while pasting the code into the script, the "then" statement was underlined red. this totally can be on me since I am new to coding though! mewtify 26 — 4y

Answer this question