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

wait() performs differently on local script vs server script?

Asked by 7 years ago
Edited 7 years ago

I am not 100% sure if the performance difference is due to local script vs server script, but I am using the following code in a local script that is stored in the player's gui section:

function foo()
    print("Hello")
        wait(0.05)
        print("Foo!")
        wait(0.05)
        if playerHasFoo then
        foo()
    end
end

When I run this code within the Roblox Studio editor, it runs quite fast. But when I publish and test this code from the Roblox Player, it seems to run a bit noticeably slower. I am using this code to make an automatic weapon that fires and the wait(0.05) is being used as a delay in between shots fired so that all the shots don't fire at once.

I have tested on multiple computers as well and I don't think it's a networking issue. I have only found 1 article on the wait() function on how to avoid lag in your projects, but it didn't really help me with this problem. I don't think I fully understand how wait() works and that is why my code is not working the way I want it to.

Any help is appreciated.

1 answer

Log in to vote
0
Answered by
unmiss 337 Moderation Voter
7 years ago
Edited 7 years ago

As far as I am concerned, testing with Studio is processed on your client. When you connect to a ROBLOX game via the actual player, the server is ran on, well, their servers, not your local machine.

This is the reason for most of the questions on this platform: "My script works in studio but not in play solo" or whatever the case may be. Know this: the server and client don't always run on the same pace. It depends on the load that you're giving them both, and even the hardware (though this wouldn't matter too much in simple script execution).

Back to the point, why do we get that question so much? Here's a little demonstration of why, given that we have a simple GUI with a local script calling to a GUIObject, let's say a frame for example.

client -->> presses play

server -->> sends information to client and loads their player in

client -->> runs local script, wait, where is the frame they were looking for

client -->> script errors, then it indexes PlayerGui and the frame loads in

I'm no expert but this is how I see it going down. The only solution really is for you to use good scripting practices—some are even in the "Guides" section of this site—and make sure to balance both loads correctly. Ensure important code is ran first, and that something you're trying to set a variable to, such as a character, has a chance to actually load in before the script runs it.

Ad

Answer this question