Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

When i tried to make a moving water It just says when i run this script "Game script Timeout?"

It just says it when i did this script!?!?

while true do 
	if script.Parent.Parent == "Workspace" then
	script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0,0.03,0)
	wait(0.07)
	else
		script.Parent.CFrame = CFrame.new(script.Parent.Position.X, 1.6,script.Parent.Position.Z)
	end
end

3 answers

✓ Accepted answer

This is due to a loop running faster than the computer can handle. To prevent freezing, or further issues, a Game Script Timeout is called, and the thread is canceled. To prevent this issue, use a wait() with a greater yield time.

However, the default return integer for wait() is an average of 0.03 seconds, so then why is 0.07 causing issues still? This is because the wait() is called within a conditional, meaning it will only tell the loop to slow down if a certain condition is true. You cannot have this, therefore, to fix your issue, rewrite the loop format to look like so:

while true do wait()
	--// Code
end

Note: I understand the wait() within your if statement has a purpose for something else, you can still keep it there, don't worry. Your code will work the same!

Well, what I assume is that you aren't giving the game time to comprehend the script. So, at the beginning or end of the while loop, put a wait(amount of time), So it should look like this:

Beginning:

while true do 
	wait(amountTime)

	--// Rest of code
end

Or at the bottom

while true do
	--// Reset of code

	wait(amountTime)
end

Doesn't really matter if you put it at the end or at the beginning.

I'm not sure if this is the exact issue, but hope this worked!

If this worked, let me know by selecting this as the answer.

~killerbrenden

You have to use wait(0.07) before or after the entire script in the while true do script.

So, the code would be:

while true do 
    wait(0.07)
    if script.Parent.Parent == "Workspace" then
    script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0,0.03,0)
    else
        script.Parent.CFrame = CFrame.new(script.Parent.Position.X, 1.6,script.Parent.Position.Z)
    end
end

Hope this helps!

-Maxis_s

This discussion is preserved as it was. New answers, comments, and votes are closed.