脚本超时:已用尽允许的执行时间(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)
repeat
until not Running

这是一个无限循环。如果您输入它,并且Runningtrue,那么您的代码将永远运行它,因为Running不会在循环体中更新。

Roblox会意识到您的代码被卡住,并抛出错误消息。

最新更新