Tweens in my script not working

Hello I have a script that was working fine and now is not and I am puzzled. This is probably due to me being a newbie and all.

The tweens inside here, none of them work and recently they all did work just fine. I moved the frame around on screen and now suddenly they do not.

local starterGui = game.StarterGui
local frame = starterGui.PotionGui.PotionPopUp:FindFirstChild("Frame")
local isOpen = starterGui.PotionGui:FindFirstChild("isOpen")
print("starterGui is " .. tostring(starterGui))
print("frame is " .. tostring(frame))

script.Parent.MouseButton1Click:connect(function()
	if isOpen.Value == true then
		isOpen.Value = false
		print ("mousclick set isOpen to " .. tostring(isOpen.Value))
	else 
		isOpen.Value = true
		print ("mousclick set isOpen to " .. tostring(isOpen.Value))
	end
end)


isOpen.Changed:Connect(function(newValue)
	if newValue == false then
		--close the frame
		frame:TweenPosition(UDim2.new(0.5, 0,0.469, 0), 'Out', 'Quad', 1)
		isOpen.Value = false
		print "tween fired and isOpen set to false"
		print (frame.Position)
	else
		--open the frame
		frame:TweenPosition(UDim2.new(0.5, 0,0.469, 0), 'Out', 'Quad', 1)
		isOpen.Value = true
		print "tween fired and isOpen set to true - it should now be open"
		print (frame.Position)
	end
end)

frame:TweenPosition(UDim2.new(1, 0,0.469, 0), 'Out', 'Sine', .5)

I added all those prints to verify things, and the script logic seems to be fine. This tween animation did work but I moved the frame around on the screen and now it doesnt.

here are some supporting images to show settings and output.

thanks for all of your help so far!

2 Likes

This should never have worked in the first place - you’re indexing the Gui through StarterGui which is just a container whose contents are cloned into PlayerGui when your character spawns

You need to use PlayerGui, a child of Player, or index using script.Parent. As you’re indexing other components through the parent, hence the prints, I’d recommend the second option.

Simply change your variables to accommodate this and you should be fine

2 Likes

Makes sense, I realize what’s going on now. Thanks!

1 Like

Sidenote: You don’t need to run an instance through tostring() to get it’s name. An instance already resolves to it’s Name property whenever turned to a string.

print(instance)

Edit: Reply below

1 Like

That would work if it were an argument alone, but he’s concatenating it & it won’t resolve the name through that (plus handling nil cases)

Oright my bad.

this all really came down to me making a foolish mistake of not using script.Parent.etc because it slipped my mind (due to lack of experience) that the Gui objects are actually copied to Workspace at server start.

I realize that now, and wont repeat that mistake.

In regards to the print, yeah I do the tostring because when i don’t, i get an error. There might be other ways to do it, but I am just using those for debugging right now.

Thanks team!