脚本超时:执行时间已用尽 (ROBLOX)

我目前在 ROBLOX 做一个个人项目,遇到了一个问题。

我正在编写一个脚本,使当玩家奔跑时,相机的视野会突然增加,就好像你真的很快一样。

我已经成功地编写了代码,但是在工作室或客户端中运行时,游戏会停止响应并在输出中显示“脚本超时:已用尽允许的执行时间”。

有什么办法可以解决吗?非常感谢!

此处为代码:

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)

原文链接 https://stackoverflow.com/questions/69860931

点赞
stackoverflow用户2858170
stackoverflow用户2858170
重复执行下面的操作:

直到 `Running` 不再为真

这是一个无限循环。如果你进入了这个循环并且 Running 是真的,你的代码将永远运行下去,因为在循环体内 Running 没有被更新。

Roblox 会意识到你的代码被卡住了,然后抛出那个错误信息。

2021-11-06 09:55:10