I am making a game for ROBLOX, and I have ran into a problem.
I am making a script so that when the player runs, the FOV of the camera will shoot up, acting like your really fast.
I have successfully made the code, however when ran in studio or the client, it freezes the game and puts a "Script Timeout: exhausted allowed execution time" in the output.
Is there any way to fix this?
Code here:
local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local player = game.Players.LocalPlayer
local Humanoid = script.Parent:WaitForChild("Humanoid")
local Camera = workspace.CurrentCamera
local FovRun = TweenService:Create(workspace.CurrentCamera, TweenInfo.new(0.5), {FieldOfView = 75})
local FovWalk = TweenService:Create(workspace.CurrentCamera, TweenInfo.new(0.5), {FieldOfView = 70})
local Running = false
UserInputService.InputBegan:Connect(function(Key, IsTyping)
if Key.KeyCode == Enum.KeyCode.LeftShift and not IsTyping then
if (Humanoid.MoveDirection:Dot(Humanoid.Parent:WaitForChild("HumanoidRootPart").CFrame.LookVector) > 0) then
if Running then
FovWalk:Play()
Running = false
Humanoid.WalkSpeed = Humanoid.WalkSpeed - 8
end
Running = true
Humanoid.WalkSpeed = Humanoid.WalkSpeed + 8
FovRun:Play()
elseif Humanoid.Health > Humanoid.MaxHealth / 1.5 then
repeat
until not Running
if Humanoid.Health < Humanoid.MaxHealth / 1.5 then
repeat
until not Running
end
else
if Running then
FovWalk:Play()
Running = false
Humanoid.WalkSpeed = Humanoid.WalkSpeed - 8
end
end
end
end)
repeat
until not Running
This is an infinite loop. If you enter it and Running
is true
your code will run it forever as Running
is not being updated in the loop's body.
Roblox will realize that your code is stuck and throw that error message.