Hello, I’m working on a new football. I’ve ran into a problem where, when I call the Travel function to Travel the football in air. I get an “script timeout: exhausted allowed execution time” error when I try to spiral the football. I’m completely clueless on why this is happening or what could be happening.
Thank for assisting.
Code:
local function Travel(Position1)
-- Check --
if not Football:GetAttribute('InAir') then
-- Update Attributes --
Football:SetAttribute('InAir',true)
Football:SetAttribute('Thrown',true)
Football:SetAttribute('Power',Power)
-- Fill In --
Position1 = Position1
-- Pre Code --
local Position2 = Mouse
local Direction = Position2 - Position1
local Duration = math.log(1.001 + Direction.Magnitude * Football:GetAttribute('Power') / 100 * 100)
local Force = Direction / Duration + Vector3.new(0,5 * Duration * 0.5,0)
-- Update Football --
Football.Position = Position1
Football.Parent = workspace
Football.AssemblyLinearVelocity = Force
Football:SetNetworkOwner(nil)
-- Spiral Settings --
local SpinRate = 0
_G.CanSpiral = true
-- Sprial Football --
while _G.CanSpiral do
SpinRate += 0.20
local BallCFrame = Football.CFrame.Position
Football.CFrame = CFrame.new(BallCFrame,BallCFrame + Football.Velocity) * CFrame.Angles(math.pi/2,math.pi * SpinRate,math.pi/2)
end
end
end
It appears your football will only stop spiraling when _G.CanSpiral is set to false so you’ll need to do that somewhere in your code whenever you want it to not spiral no more.
Inside the actual football. I made it so that _CanSpiral should stop. But when I run the command to check what the Global Variable’s current status is. It returns and nil.
globals or _G are only shared across the same environment I’m assuming one of these scripts is a local script and the other is a regular script. In that case, you won’t be able to access _G.CanSpiral and will need to utilize RemoteEvents or possibly Attributes depending on how you wanna go about it.
EDIT: I just realized you ran the code in the command bar which executed that print statement on the client rather than the server which is why it returned nil
The command bar is on a different environment than actual script instances that is why it is returning nil. You’d have to create a script instance with that print inside of it in order to see what the value actually is.
Nvm. It’s because in the touch function. It would only call spiral if the ball touched a character first. All I had to do was change where I changed _Spiral too.