Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does my script perform random errors when clicked in GUI?

Asked by 6 years ago
Edited 6 years ago

[Edit 19/5/2018 V2]

This is my select the gamemode gui. I changed it into different bright colours to see the performance better.

It works perfectly. However, sometimes, it changes randomly and I do not know why. By watching the link below, you notice that the previous button does not transition efficiently. It does work but unexpectedly it glitches out. I cannot find anything wrong with it. Any ideas?

VideoLink

As you can see in the video, the runs perfectly on the first run but does random things after that. What is the problem here?


-- Declaration Section -- / Player Precedence local Player = game:GetService("Players").LocalPlayer local PlayerGui = Player:WaitForChild("PlayerGui") local Gui = PlayerGui:FindFirstChild("Gui") -- / List of Actual Frames local frameList = { [1] = Gui.frame0, [2] = Gui.frame1, [3] = Gui.frame2, [4] = Gui.frame3, [5] = Gui.frame4, [6] = Gui.frame5, [7] = Gui.frame6 } local CurrentFrame = 1 -- / Configuration for the movement of the frames local AnimationLength = 0.5 local AnimationStyle = Enum.EasingStyle.Sine local AnimationDirection = Enum.EasingDirection.Out -- / Buttons local previousButton = Gui.Previous local nextButton = Gui.Next -- Processing Section local function ChangeFrames(MovingFramesArray) for i, FrameData in pairs(MovingFramesArray) do if FrameData == nil then return end FrameData[1]:TweenSizeAndPosition(FrameData[2] or FrameData[1].Size, FrameData[3] or FrameData[1].Position, AnimationDirection, AnimationStyle, AnimationLength) end end nextButton.MouseButton1Down:Connect(function(x, y) if not frameList[CurrentFrame + 1] then return end CurrentFrame = CurrentFrame + 1 -- The following data layout is: {Frame-Object, New-Size, New-Position} local newFrameData = {frameList[CurrentFrame], UDim2.new(0, 405, 0, 370), UDim2.new(1, -650, 1, -500)} local oldFrameData local newBackgroundFrameData local oldBackgroundFrameData if frameList[CurrentFrame - 1] then oldFrameData = {frameList[CurrentFrame - 1], UDim2.new(0, 320, 0, 292), UDim2.new(1, -950, 1, -450)} oldFrameData.ZIndex = 1 end if frameList[CurrentFrame + 1] then newBackgroundFrameData = {frameList[CurrentFrame + 1], UDim2.new(0, 320, 0, 292), UDim2.new(1, -300, 1, -450)} newBackgroundFrameData.ZIndex = 1 end if frameList[CurrentFrame - 2] then oldBackgroundFrameData = {frameList[CurrentFrame - 2], UDim2.new(0, 0, 0, 0), UDim2.new(1, -1250, 1, -450)} oldBackgroundFrameData.ZIndex = 1 end ChangeFrames({newFrameData, oldFrameData, newBackgroundFrameData, oldBackgroundFrameData}) end) previousButton.MouseButton1Down:Connect(function(x, y) if not frameList[CurrentFrame - 1] then return end CurrentFrame = CurrentFrame - 1 -- Same data layout: {Frame-Object, New-Size, New-Position} local newFrameData = {frameList[CurrentFrame], UDim2.new(0, 405, 0, 370), UDim2.new(1, -650, 1, -500)} local oldFrameData local newBackgroundFrameData local oldBackgroundFrameData if frameList[CurrentFrame + 1] then oldFrameData = {frameList[CurrentFrame + 1], UDim2.new(0, 320, 0, 292), UDim2.new(1, -300, 1, -450)} oldFrameData.ZIndex = 1 end if frameList[CurrentFrame - 1] then newBackgroundFrameData = {frameList[CurrentFrame - 1], UDim2.new(0, 320, 0, 292), UDim2.new(1, -950, 1, -450)} newBackgroundFrameData.ZIndex = 1 end if frameList[CurrentFrame + 2] then oldBackgroundFrameData = {frameList[CurrentFrame + 2], UDim2.new(0, 0, 0, 0), UDim2.new(1, 0, 1, -450)} oldBackgroundFrameData.ZIndex = 1 end ChangeFrames({newFrameData, oldFrameData, newBackgroundFrameData, oldBackgroundFrameData}) end)

Help?

0
I'm not to sure, but by the looks of it it only bugs out when you're going to click the previous button hunterthegreat100 18 — 6y
0
Yes. That is exactly the problem. Axceed_Xlr 380 — 6y
0
Are you checking the Output Kulh 125 — 6y
0
^ No errors are seen. Axceed_Xlr 380 — 6y

1 answer

Log in to vote
0
Answered by
hellmatic 1523 Moderation Voter
6 years ago
Edited 6 years ago

Don't add or subtract the CurrentFrame because if the Player spam clicks the button, the CurrentFrame's value can go to a high positive or negative number (-50 or 50). This can cause it to bug out.

Instead, add a variable to each frame (Showing = false) to identify if it is showing or not.

local Settings = {
        Enabled = true 

    ,FrameOne = {
        Showing = true 
        }

    ,FrameTwo = {
        Showing = false 
        }

    ,FrameThree = {
        Showing = false 
        }
    }

Next function:

local nextButton = Gui.Next
local previousButton = Gui.Previous

-- Assuming that FrameOne is already showing

function Next()
    if not Settings.FrameTwo.Showing and FrameOne.Showing then -- if Frame1 is showing, shows Frame2
        Settings.FrameTwo.Showing = true 
        Settings.FrameOne.Showing = false 
        --code
        print('showing frame 2')

    elseif not Settings.FrameThree.Showing and FrameTwo.Showing then -- if Frame2 is showing, shows Frame3
        Settings.FrameThree.Showing = true 
        Settings.FrameTwo.Showing = false 
        --code
        print('showing frame 3')
    end
end

Previous function:

local nextButton = Gui.Next
local previousButton = Gui.Previous

function Back()
    if not Settings.FrameOne.Showing and Settings.FrameTwo.Showing then -- if Frame2 is showing, shows Frame1
        Settings.FrameOne.Showing = true 
        Settings.FrameTwo.Showing = false 
        --code
        print('showing frame 1')

    elseif not Settings.FrameTwo.Showing and Settings.FrameThree.Showing then -- if Frame3 is showing, shows Frame2
        Settings.FrameTwo.Showing = true 
        Settings.FrameThree.Showing = false 
        --code
        print('showing frame 2')
    end
end
Ad

Answer this question