Hello!
I am trying to make a rolling effect gui on my game. I am adding all types of effects to make this all possible (Using Tween Service).
For some reason, My script crashes/timeouts for no reason when the “Auto Roll” value is true. I’m a bit confused on why and apparantly the error is this:
Script timeout: exhausted allowed execution time - Client
08:43:42.185 Stack Begin - Studio
08:43:42.185 Script 'Players.spvp1234.PlayerGui.GameSystem.RollingSystem.ExecuteRoll.RollClient', Line 317
Here is the local script handling the player rolls:
local Players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")
local TS = game:GetService("TweenService")
local LS = game:GetService("Lighting")
local MPS = game:GetService("MarketplaceService")
local SS = game:GetService("SoundService")
--//Guis
local ExecuteRollGui = script.Parent
local DimensionsInventoryGui = ExecuteRollGui.Parent.DimensionsInventory
local Background = ExecuteRollGui.Background
local RollButton = Background.RollButton
local RolledScreen = script.Parent.RolledScreen
local LoadingScreen = script.Parent.LoadingScreen
local LoadingCircle = LoadingScreen.LoadingCircle
local LoadingText = LoadingScreen.Text
--//Player
local Player = Players.LocalPlayer
--//Remotes and Bindables
local RollingSystemRemotes = RS:WaitForChild("Client").GameSystem.RollingSystem
local Rolled = RollingSystemRemotes.Rolled
local Events = ExecuteRollGui.Parent.Events
local RolledBindable = Events.Rolled
--//Variables
local TargetFOV = 67
local TargetTransparency = 0.65
local TargetBlur = 56
local EndColor = Color3.fromRGB(255,255,255)
local Clicked = false
local QuickRollID = 783234515
local AutoRoll = Background.AutoRoll.AutoRoll
local ClickSound = SS:WaitForChild("ClientGui").ClickSound
local Above9Sound = script.Above9
local SpecialRolledScreenSound = script.SpecialRolledScreenSound
local LowRumbleSound = script.LowRumble
--//Functions
function ToggleRollButtonVisibility()
if RollButton.Visible == true then
RollButton.Visible = false
Background.Visible = false
elseif RollButton.Visible == false then
RollButton.Visible = true
Background.Visible = true
end
end
function PrepareRolledScreen(RollType, StatsEarned)
RolledScreen.DemensionType.Text = RollType[1]
RolledScreen.DemensionType.TextColor3 = RollType[3]
RolledScreen.DemensionRarity.Text = RollType[2]
RolledScreen.XPEarned.Text = "Earned "..StatsEarned[1].." XP."
RolledScreen.MoneyEarned.Text = "Earned $"..StatsEarned[2].."."
end
function PrepareLoadingScreen(RollType)
LoadingCircle.ImageColor3 = RollType[3]
end
function ReplicateRolledScreen(RollType, StatsEarned, RolledScreenWaitTime)
--Camera
local Camera = workspace.CurrentCamera
local CamInfo = TweenInfo.new(0.7, Enum.EasingStyle.Quart)
local CamTweenEnter = TS:Create(Camera, CamInfo, {FieldOfView = TargetFOV})
local CamTweenOut = TS:Create(Camera, CamInfo, {FieldOfView = 70})
--Blur
local BlurInfo = TweenInfo.new(0.7, Enum.EasingStyle.Quart)
local BlurTweenEnter = TS:Create(LS.GuiBlur, BlurInfo, {Size = TargetBlur})
local BlurTweenOut = TS:Create(LS.GuiBlur, BlurInfo, {Size = 0})
--RolledScreen
local RolledScreenInfoEnter = TweenInfo.new(0.7, Enum.EasingStyle.Quart, Enum.EasingDirection.In)
local RolledScreenInfoOut = TweenInfo.new(0.7, Enum.EasingStyle.Quart, Enum.EasingDirection.Out)
local RolledScreenTweenEnter = TS:Create(RolledScreen, RolledScreenInfoEnter, {BackgroundTransparency = TargetTransparency})
local RolledScreenTweenOut = TS:Create(RolledScreen, RolledScreenInfoOut, {BackgroundTransparency = 1})
print("Tweens created.")
PrepareRolledScreen(RollType, StatsEarned)
--Action and Connection
RolledScreen.Visible = true
ToggleRollButtonVisibility()
--Enter
DimensionsInventoryGui.Enabled = false
CamTweenEnter:Play()
BlurTweenEnter:Play()
RolledScreenTweenEnter:Play()
for i, Child in pairs(RolledScreen:GetChildren()) do
if Child:IsA("TextLabel") then
local ChildTween = TS:Create(Child, RolledScreenInfoEnter, {TextTransparency = 0})
ChildTween:Play()
end
end
print("Enter completed.")
--Out
task.wait(RolledScreenWaitTime)
print("Out starting.")
CamTweenOut:Play()
BlurTweenOut:Play()
RolledScreenTweenOut:Play()
for i, Child in pairs(RolledScreen:GetChildren()) do
if Child:IsA("TextLabel") then
local ChildTween = TS:Create(Child, RolledScreenInfoOut, {BackgroundTransparency = 1, TextTransparency = 1})
ChildTween:Play()
end
end
ToggleRollButtonVisibility()
DimensionsInventoryGui.Enabled = true
--Reset RolledScreen
RolledScreenTweenOut.Completed:Connect(function()
RolledScreen.Visible = false
end)
end
function ReplicateSpecialEffectRollingScreen(RollType, StatsEarned, RolledScreenWaitTime)
local RolledScreenWaitTime = 5
--Camera
local Camera = workspace.CurrentCamera
local CamInfo = TweenInfo.new(0.3, Enum.EasingStyle.Quart)
local CamTweenEnter = TS:Create(Camera, CamInfo, {FieldOfView = TargetFOV})
local CamTweenOut = TS:Create(Camera, CamInfo, {FieldOfView = 70})
--Blur
local BlurInfoEnter = TweenInfo.new(0.3, Enum.EasingStyle.Quart)
local BlurInfoOut = TweenInfo.new(0.7, Enum.EasingStyle.Quart)
local BlurTweenEnter = TS:Create(LS.GuiBlur, BlurInfoEnter, {Size = TargetBlur})
local BlurTweenOut = TS:Create(LS.GuiBlur, BlurInfoOut, {Size = 0})
--LoadingScreen
local LoadingScreenInfoEnter = TweenInfo.new(0.3, Enum.EasingStyle.Quart, Enum.EasingDirection.In)
local LoadingScreenInfoOut = TweenInfo.new(0.7, Enum.EasingStyle.Quart, Enum.EasingDirection.Out)
local LoadingScreenTweenEnter = TS:Create(LoadingScreen, LoadingScreenInfoEnter, {BackgroundTransparency = 0})
local LoadingScreenTweenOut = TS:Create(LoadingScreen, LoadingScreenInfoOut, {BackgroundTransparency = 1})
--Color
local ColorInfo = TweenInfo.new(3, Enum.EasingStyle.Exponential)
local ColorTween = TS:Create(LoadingScreen, ColorInfo, {BackgroundColor3 = EndColor})
--RolledScreen
local RolledScreenInfoOut = TweenInfo.new(0.7, Enum.EasingStyle.Quart, Enum.EasingDirection.Out)
local RolledScreenTweenOut = TS:Create(RolledScreen, RolledScreenInfoOut, {BackgroundTransparency = 1})
PrepareLoadingScreen(RollType)
PrepareRolledScreen(RollType, StatsEarned)
--Action and Connection
LoadingScreen.Visible = true
ToggleRollButtonVisibility()
--Enter
DimensionsInventoryGui.Enabled = false
CamTweenEnter:Play()
BlurTweenEnter:Play()
LoadingScreenTweenEnter:Play()
Above9Sound:Play()
for i, Child in pairs(LoadingScreen:GetChildren()) do
if Child:IsA("TextLabel") then
local ChildTween = TS:Create(Child, LoadingScreenInfoEnter, {TextTransparency = 1})
ChildTween:Play()
elseif Child:IsA("ImageLabel") then
local ChildTween = TS:Create(Child, LoadingScreenInfoEnter, {ImageTransparency = 0})
ChildTween:Play()
end
end
LowRumbleSound:Play()
--Middle of Event
LoadingScreenTweenEnter.Completed:Connect(function()
print("Entered Loading Screen")
task.wait(4)
RolledScreen.BackgroundTransparency = TargetTransparency
RolledScreen.Visible = true
ColorTween:Play()
--Into RolledScreen
ColorTween.Completed:Connect(function()
print("Completed color")
task.wait(2)
LowRumbleSound:Stop()
SpecialRolledScreenSound:Play()
LoadingScreenTweenOut:Play()
for i, Child in pairs(LoadingScreen:GetChildren()) do
if Child:IsA("TextLabel") then
local ChildTween = TS:Create(Child, LoadingScreenInfoOut, {BackgroundTransparency = 1, TextTransparency = 1})
ChildTween:Play()
elseif Child:IsA("ImageLabel") then
local ChildTween = TS:Create(Child, LoadingScreenInfoEnter, {ImageTransparency = 1})
ChildTween:Play()
end
end
LoadingScreenTweenOut.Completed:Connect(function()
for i, Child in pairs(RolledScreen:GetChildren()) do
if Child:IsA("TextLabel") then
Child.TextTransparency = 0
end
end
LoadingScreen.Visible = false
--Out
task.wait(RolledScreenWaitTime)
CamTweenOut:Play()
BlurTweenOut:Play()
RolledScreenTweenOut:Play()
for i, Child in pairs(RolledScreen:GetChildren()) do
if Child:IsA("TextLabel") then
local ChildTween = TS:Create(Child, RolledScreenInfoOut, {TextTransparency = 1})
ChildTween:Play()
end
end
ToggleRollButtonVisibility()
DimensionsInventoryGui.Enabled = true
--Reset RolledScreen
RolledScreenTweenOut.Completed:Connect(function()
RolledScreen.Visible = false
LoadingScreen.BackgroundColor3 = Color3.fromRGB(0,0,0)
end)
end)
end)
end)
end
function ClickedRollButton()
if Clicked == false then
Clicked = true
ClickSound:Play()
local RollType, StatsEarned, PlayerData = Rolled:InvokeServer()
if RollType[4] <= 9 then
if MPS:UserOwnsGamePassAsync(Player.UserId, QuickRollID) and PlayerData["QuickRoll"] == true then
ReplicateRolledScreen(RollType, StatsEarned, 0.5)
print("Passed replication")
local ButtonFrame = Instance.new("Frame")
ButtonFrame.Visible = false
ButtonFrame.AnchorPoint = Vector2.new(0,0.5)
ButtonFrame.Size = UDim2.fromScale(1,1)
ButtonFrame.Position = UDim2.fromScale(0,0.5)
ButtonFrame.BackgroundColor3 = Color3.fromRGB(54, 54, 54)
Background.BackgroundTransparency = 0.5
ButtonFrame.Parent = RollButton
ButtonFrame.Visible = true
local ButtonTweenInfo = TweenInfo.new(1, Enum.EasingStyle.Exponential)
local Tween = TS:Create(ButtonFrame, ButtonTweenInfo, {Size = UDim2.fromScale(0,1)})
Tween:Play()
print("Played Tween")
Tween.Completed:Connect(function()
ButtonFrame:Destroy()
Clicked = false
RolledBindable:Fire(PlayerData)
end)
else
ReplicateRolledScreen(RollType, StatsEarned, 3)
local ButtonFrame = Instance.new("Frame")
ButtonFrame.Visible = false
ButtonFrame.AnchorPoint = Vector2.new(0,0.5)
ButtonFrame.Size = UDim2.fromScale(1,1)
ButtonFrame.Position = UDim2.fromScale(0,0.5)
ButtonFrame.BackgroundColor3 = Color3.fromRGB(54, 54, 54)
Background.BackgroundTransparency = 0.5
ButtonFrame.Parent = RollButton
ButtonFrame.Visible = true
local ButtonTweenInfo = TweenInfo.new(1, Enum.EasingStyle.Exponential)
local Tween = TS:Create(ButtonFrame, ButtonTweenInfo, {Size = UDim2.fromScale(0,1)})
Tween:Play()
print("Played Tween")
Tween.Completed:Connect(function()
ButtonFrame:Destroy()
Clicked = false
RolledBindable:Fire(PlayerData)
end)
end
elseif RollType[4] > 9 then
ReplicateSpecialEffectRollingScreen(RollType, StatsEarned, 5)
local ButtonFrame = Instance.new("Frame")
ButtonFrame.Visible = false
ButtonFrame.AnchorPoint = Vector2.new(0,0.5)
ButtonFrame.Size = UDim2.fromScale(1,1)
ButtonFrame.Position = UDim2.fromScale(0,0.5)
ButtonFrame.BackgroundColor3 = Color3.fromRGB(54, 54, 54)
Background.BackgroundTransparency = 0.5
ButtonFrame.Parent = RollButton
ButtonFrame.Visible = true
local ButtonTweenInfo = TweenInfo.new(2, Enum.EasingStyle.Exponential)
local Tween = TS:Create(ButtonFrame, ButtonTweenInfo, {Size = UDim2.fromScale(0,1)})
Tween:Play()
Tween.Completed:Connect(function()
ButtonFrame:Destroy()
Clicked = false
RolledBindable:Fire(PlayerData)
end)
end
end
end
--//Connections
RollButton.MouseButton1Click:Connect(ClickedRollButton)
AutoRoll:GetPropertyChangedSignal("Value"):Connect(function()
if AutoRoll.Value == true then
while AutoRoll.Value == true do
ClickedRollButton()
end
end
end)```