Script keeps timing out?

So I have this script that keeps timing out, and I tried everything using the “dog == false”

dog = false

local player = game.Players.LocalPlayer

repeat wait(1) until player.Character

local character = player.Character

local humanoid = character:WaitForChild("Humanoid")

local animation = Instance.new("Animation")

animation.Name = "Idle"

animation.Parent = script.Parent

animation.AnimationId = "http://www.roblox.com/asset/?id=" .. "4376204956"

rat = false

local animtrack = humanoid:LoadAnimation(animation)

script.Parent.Equipped:connect(function()

animtrack:Play()

rat = true

end)

script.Parent.Unequipped:connect(function()

animtrack:Stop()

end)

while true do

if rat == true and dog == false then

dog = true

wait(120)

script.Parent.ColdGiver:FireServer()

end

end
1 Like

@Pooglies Can you show a picture of the output error message?

image

1 Like

Can you send a picture of the actual script so I can see whats on line 29 thats making it time out?

Your while loop will only yield if the if statement passes, overwise it’s repeating too quickly causing a timeout.
I recommend putting a wait() or something to yield inside.
Eg.

while true do
    if rat and not dog then
        dog = true
        wait(120)
        script.Parent.ColdGiver:FireServer()
    end
    wait()
end
dog = false

local player = game.Players.LocalPlayer

repeat wait(1) until player.Character

local character = player.Character

local humanoid = character:WaitForChild("Humanoid")

local animation = Instance.new("Animation")

animation.Name = "Idle"

animation.Parent = script.Parent

animation.AnimationId = "http://www.roblox.com/asset/?id=" .. "4376204956"

rat = false

local animtrack = humanoid:LoadAnimation(animation)

script.Parent.Equipped:connect(function()

animtrack:Play()

rat = true

end)

script.Parent.Unequipped:connect(function()

animtrack:Stop()

end)

while true do

if rat == true and dog == false then

dog = true

wait(120)

script.Parent.ColdGiver:FireServer()

end

end
dog = false

local player = game.Players.LocalPlayer

repeat wait(1) until player.Character

local character = player.Character

local humanoid = character:WaitForChild("Humanoid")

local animation = Instance.new("Animation")

animation.Name = "Idle"

animation.Parent = script.Parent

animation.AnimationId = "http://www.roblox.com/asset/?id=" .. "4376204956"

rat = false

local animtrack = humanoid:LoadAnimation(animation)

script.Parent.Equipped:connect(function()

animtrack:Play()

rat = true

end)

script.Parent.Unequipped:connect(function()

animtrack:Stop()

end)

while true do
wait()
if rat == true and dog == false then

dog = true

wait(120)

script.Parent.ColdGiver:FireServer()

end

end

Try this :slight_smile:

DevConX is asking for a screenshot with the line numbers on the left side, we can’t tell what line 29 is the script itself as easily (for future reference)
RobloxStudioBeta_81qlcgrVXF
Though it does appear to be that if rat isn’t true or dog isn’t false, it’s basically a while true do loop which would cause a timeout; the script would run as fast as it possibly can indefinitely, leaving no time for anything else to happen, hence a timeout.

line 36: while true do
timeout came from not adding any intervals, try:
while true do wait()

Hope this helps :slight_smile: