Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My Close and Open Gui Animation does not work?

I have this script that test if the Gui is on or off (Open or Closed) The problem is probably the for i in pairs(Numbers) do

Script:

local Box = script.Parent.Main
local Open = script.Parent.Button.IsOpen

if Open == false then
	script.Parent.Button.BackgroundColor3.r = 94
	script.Parent.Button.BackgroundColor3.g = 211
	script.Parent.Button.BackgroundColor3.b = 4
	for i in pairs(0,-220,0.3,0) do -- "1"
		Box.Position.X.Offset(i)
	end
else
	script.Parent.Button.BackgroundColor3.r = 211 -- It starts saying that the problem is here. So the script could actually be stopped from "1"
	script.Parent.Button.BackgroundColor3.g = 25
	script.Parent.Button.BackgroundColor3.b = 0
	for i in pairs(0,0,0.3,0) do -- "2"
		Box.Position.X.Offset(i)
	end
end

2 comments

1

I assume that this entire block of code has to be either in a function or has to be looped because it will only check your statement the one time the code is run.

0

The script is working on the same way if it is looping or not. It is the Animations that have the Problem but I can't find out what it is.

1 answer

Problem

So the possible problems I see with your script is checking if an Instance is true instead of checking if a value is true and checking it only ONCE. Also, it might be possible that you used the RGB coloring wrong.

Solution

So first of all, we will need to add .Value to your IsOpen and add a variable for the actual instance instead of the value.

Result:

local Open = script.Parent.Button.IsOpen.Value
local OpenInstance = script.Parent.Button.IsOpen -- we will need this value for something

Alright, your script still doesn't work? You'll need to add the Changed event. It fires everytime the value changes. (wiki)

The result would be this: (I fixed the RGB.)

local Box = script.Parent.Main
local Open = script.Parent.Button.IsOpen.Value
local OpenInstance = script.Parent.Button.IsOpen

if Open == false then
    script.Parent.Button.BackgroundColor3 = Color3.fromRGB(94, 211, 4)
    for i in pairs(0,-220,0.3,0) do -- "1"
        Box.Position.X.Offset(i)
    end
else
    script.Parent.Button.BackgroundColor3 = Color3.fromRGB(211, 25, 0)
    for i in pairs(0,0,0.3,0) do -- "2"
        Box.Position.X.Offset(i)
    end
end

Note, I did not check the script so make sure to comment or ping me in the chat if something happens.

This discussion is preserved as it was. New answers, comments, and votes are closed.