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

Why does my OpenShop Text Button only run once?

Asked by 3 years ago

I am making a shop GUI in my game and I've made the button to open it and a button on the ScrollingFrame itself, and when I click the close button, the Open shop button won't work.

Code for the Open Button:

local object = script.Parent.Parent.Parent.ScrollingFrame
object.AnchorPoint = Vector2.new(0.5, 0.5)

object.Position = UDim2.new(-1, 0, 0.5, 0)

script.Parent.MouseButton1Click:Connect(function()
    object:TweenPosition(UDim2.new(0.5, 0, 0.5, 0))
end)

Code for the Close Button:

script.Parent.MouseButton1Click:Connect(function()
    script.Parent.Parent.Visible = false
end)

I am quite new to scripting so please don't talk about my poor coding skills :)

0
When you click the button the first time, you move the "object" to the position given, the other times you click the button, it's already at that position so nothing changes Spjureeedd 385 — 3y
0
Have you tried tweening it back to the original position rather than just making the GUI invisible? If you're trying to achieve a fluent shop animation, it'd only make sense to do so. DeceptiveCaster 3761 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

Its only running a single time because when opening it it just moves it to another position and when closing the is made invisble. The button is actually working but the gui stays invisible when you want it to be visible.

Use this script for the open buttom instead of your current.

Please place your UI in the place you want it to be on the players screen.

Next go in properties and uncheck visible.

Open button script:

script.Parent.MouseButton1Click:Connect(function()
    script.Parent.Parent.Visible = false
    script.Parent.Parent.parent.OPENFRAMENAME.Visible = true
end)


Ad
Log in to vote
-1
Answered by 3 years ago

Code for the Close Button:

script.Parent.Parent.Visible = false
script.Parent.MouseButton1Click:Connect(function()
    script.Parent.Parent.Visible = not  script.Parent.Parent.Visible
end)
1
This toggles the visibility, it's not specifically a close button then Spjureeedd 385 — 3y
0
-1 for spoonfeeding DeceptiveCaster 3761 — 3y

Answer this question