My tween only plays once

I want my tween to play each time someone click a part and a gui is tweened on to the screen. I click it, it work but when I remove it and click it again it doesn’t play it.

Here is my code:
local RP = game:GetService(“ReplicatedStorage”)

local Shop = script.Parent.Parent
local Frame = Shop.Frame
local TweenService = game:GetService("TweenService")

local PPService = game:GetService("ProximityPromptService")
local PP = game.Workspace.SpecShopPart.ProximityPrompt

local ShopAppear = RP.SpecShop
local button = game.Workspace.SpecShopPart.SurfaceGui.Frame.TextButton

local One = script.Parent.Text.One
local Two = script.Parent.Text.Two

local On = game.Workspace.SpecShopPart.On


Frame.Visible = false

On.Value = false

local AppearTween = TweenInfo.new(1,Enum.EasingStyle.Back,Enum.EasingDirection.Out)
local tweenA = TweenService:Create(script.Parent,AppearTween,{Position=UDim2.new(0.138,0,0.712,0)})

while wait() do
	if On.Value == false then
		button.Activated:Connect(function()
			Frame.Visible = true
			tweenA:Play()
			On.Value = true	
			One.Value = true	
		end)
	end
end
2 Likes

You need to add a wait of 1 second because every time the loop runs, the tween starts from zero again.

1 Like

I added a wait in the while wait do loop but it didnt work

Your if statement here checks if the “On” value is false, you never set it back to false, hence the code just ends as there is nothing to do.

Try setting the value to false again when your finished doing what you need to do.

1 Like

I put it so that it turns false when clicked the close option and it does open it just doesnt play the tween or else everything is fine.

Could you show where your setting this value back to false, it could be that you pick up the value on the server, but then change it on the client meaning the server never picks it up as being changed.

1 Like

I have two scripts to change it, one where you would say bye and one where if you complete what the person says and it open a gui here are the scripts:

Bye script:
local close = script.Parent

local On = game.Workspace.SpecShopPart.On

local One = script.Parent.Parent.Text.One

local Two = script.Parent.Parent.Text.Two

local Button = script.Parent.Parent.Text

local Hello = script.Parent.Parent.Text.Hello

local Text = script.Parent.Parent.TextLabel

close.Activated:Connect(function()

script.Parent.Parent.Visible = false
    On.Value = false
    One.Value = false
    Two.Value = false
    Button.Text = Hello.Value
    Text.Text = "Hello, what can I help you with?"
end)

Complete dialogue script:

local Hello = script.Parent.Hello
local Look = script.Parent.Look

local On = game.Workspace.SpecShopPart.On
local closing = script.Parent.Closing

local One = script.Parent.One
local Two = script.Parent.Two

local Button = script.Parent
local Text = script.Parent.Parent.TextLabel

local Frame = script.Parent.Parent

while true do 
	wait()
	if On.Value == false then
		One.Value = false
		Two.Value = false
		Button.Text = Hello.Value
		Text.Text = "Hello,  what can I help you with?"
	end
end

Extra script where it changes the text and all:
local Hello = script.Parent.Hello
local Look = script.Parent.Look

local Shop = script.Parent.Parent.Parent.Shop

local On = game.Workspace.SpecShopPart.On
local closing = script.Parent.Closing

local One = script.Parent.One
local Two = script.Parent.Two

local Button = script.Parent
local Text = script.Parent.Parent.TextLabel

local Frame = script.Parent.Parent

local TweenService = game:GetService("TweenService")
local ShopOpen = TweenInfo.new(1,Enum.EasingStyle.Back,Enum.EasingDirection.Out)
local tweenB = TweenService:Create(Shop,ShopOpen,{Position=UDim2.new(.26, 0,0.19, 0)})


while true do
	wait()
	if On.Value == true and One.Value == true then
		Button.Text = Hello.Value
		break
	end
end



Button.Activated:Connect(function()
	wait(1)
	One.Value = false
	Two.Value = true
	Button.Text = Look.Value
	Text.Text = "Alright, take a look at my shop!"
	closing.Value = true
end)

Button.Activated:Connect(function()
	if Button.Text == "Ok" then
		wait(1)
		Frame.Visible = false
		On.Value = false
		tweenB:Play()
		script.Parent.Parent.Parent.Shop.Visible = true
	end
end)

(tweenB is to open the shop) and I am sorry if this is alot :cold_sweat:

Assuming “close” is a button, you would want to use the .MouseButton1Click event for this, same with your other parts in the code, instead of .Activated, you should use MouseButton1Click.

As far as the rest goes, make sure your checking you have the right values, etc.

Could you tell me if these are both scripts? I’m confident this is most likely a value issue or an issue with the script locations

1 Like

I don’t understand the part wether if it is a script but I changed all the activated with the MouseButton1Click event and it didn’t change anything. And they are all local scripts if that is what you meant

Ok, where are your values located? (The Activated changes we’re just for better practise)

1 Like

The On value is in the part it self that you have to click, but all the rest is in the button that lies within the frame of the dialogue.

Interesting, are all the scripts local scripts?

Yes they are all local scripts located in the GUI

Hmm, I’ll take a look through the code again and see if I can spot anything, apologies, I’m quite tired today so I can be a bit slow.

(If anyone else is watching this topic and has any idea, please chime in :slight_smile: )

1 Like

No, no take your time! I don’t wanna trouble you

1 Like

I don’t see that you getting your GUI back on start place. I mean, your GUI just getting to the end position with Tweening but if you click again it just appears on same place where tween ended? I need more answers. If it’s just appears on same place where tween was ended, then make sure to move gui back when making it’s not visible.

2 Likes

Thank you so much it worked!! I did not think of that. And @VoidException I am so sorry for wasting you time like this :frowning:

3 Likes

No waste of time at all! My fault, have a great day :slight_smile:

2 Likes