Issue with tweening GUI

Hello!

I’m having an issue with my GUI that makes it not move when the BindableEvent is being fired. It’s in a localscript. Other functions in the exact same script use the same code, and it still tweens when using those functions so I’m not too sure as to what’s going on.

function win(winnername)
	warn("Function win") -- It's being printed.
	
    local winf

    if not winf == true then
		winf = true
		wait()
		local newpos = UDim2.new(0.5, 0, 0.5, 0)
		local oldpos = UDim2.new(0.5, 0, 2, 0)
		script.Parent.Parent:TweenPosition(newpos, Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 0.5) 
		wait(.1)
		local playerUsername = game.Players.LocalPlayer.Name		

		local ReplicatedStorage = game:GetService("ReplicatedStorage")

		local TypeWriter = require(ReplicatedStorage:WaitForChild("TypeWriter"))
		TypeWriter.typeWrite(script.Parent, "Game Over! "..winnername.." has won the game.")
	
		wait(2)
	
		script.Parent.Parent:TweenPosition(oldpos, Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 0.5)
	
		script.Parent.Text = "Waiting for map..."
	else 
		return
	end
	
end

TIA for helping!

1 Like

Have you tried using Connect? This may be the reason why the script is not working, as the function has yet to be called.

1 Like

Sorry, late reply.
Yeah, I used :Connect. I’ve added how it’s been fired below:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local newPlayerEvent = ReplicatedStorage:WaitForChild("EliminatedPlayer")

local gameEnd = game.ReplicatedStorage.WinnerPopup

gameEnd.OnClientEvent:Connect(win)

You stated that

Does the warning output? The only thing that seems off about this code so far is the winf variable. I think the code should have local winf = false outside the function.

1 Like

It may be that you’re using

script.Parent.Parent:TweenPosition(oldpos, Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 0.5)

instead of

		script.Parent.Parent:TweenPosition(newpos, Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 0.5)

Assuming that you would like to tween the UI to the new position, then you may have misused the variables.

1 Like

Yeah, it outputs.

It’s supposed to first tween to the first position (on screen), then after the wait, it tweens to the old position (off screen).

Change if not winf == true then to if not winf then. Also, try having local winf = false outside the function since it’s currently not accessible outside the function which will most likely cause it to not work as intended.

1 Like

No luck unfortunately.

Edit: Should add that the boolean variable is there to keep it from running more than once.

Strange. Have you tried using any print statements to see where the issue starts? Are there any errors as well?

1 Like

No errors, I’ll try adding a few prints.

1 Like

It stops somewhere after “start tween” as “start tween”, as well as “not winf” are being printed, but nothing else.

		print("not winf")
		winf = true
		wait()
		print("start tween")
		local newpos = UDim2.new(0.5, 0, 0.5, 0)
		local oldpos = UDim2.new(0.5, 0, 2, 0)
		script.Parent.Parent:TweenPosition(newpos, Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 0.5) 
		wait(.1)
		local playerUsername = game.Players.LocalPlayer.Name		
		print("user")
		local ReplicatedStorage = game:GetService("ReplicatedStorage")
		
		print("rs")
			
		local TypeWriter = require(ReplicatedStorage:WaitForChild("TypeWriter"))
		TypeWriter.typeWrite(script.Parent, "Game Over! "..winnername.." has won the game.")
		wait(2)
	
		script.Parent.Parent:TweenPosition(oldpos, Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 0.5)
	
		script.Parent.Text = "Waiting for map..."

I tested out the script and it worked fine for me. It seems like it may be something wrong with script.Parent.Parent.

Possibly, I’ll try switching that around and let you know.

Edit: There doesn’t seem to be an issue, I’ll add another function that does work, it’s basically the same thing. I don’t see any differences between them, but if you want to look, maybe you’ll have a better eye than me haha.

Script:
function textadd(mapName)
	local newpos = UDim2.new(0.5, 0, 0.5, 0)
	local oldpos = UDim2.new(0.5, 0, 2, 0)
	
	script.Parent.Text = "Loading Map..."
	
	script.Parent.Parent:TweenPosition(newpos, Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 0.5) 
	
	wait(.1)
	local map = game.Workspace.Maps:FindFirstChildOfClass("Model")
	wait(map:WaitForChild("Settings"))
	local playerUsername = game.Players.LocalPlayer.Name
	
	-- Roblox services
	local ReplicatedStorage = game:GetService("ReplicatedStorage")
	 
	-- Require module
	local TypeWriter = require(ReplicatedStorage:WaitForChild("TypeWriter"))
	TypeWriter.typeWrite(script.Parent, mapName.Settings.MapName.Value.." by "..mapName.Settings.Creator.Value.." has been chosen.")
	wait(2)
	script.Parent.Parent:TweenPosition(oldpos, Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 0.5)
	
	script.Parent.Text = "Waiting for map..."
end

Not sure why there’s so much red, sorry about that.

Decided I’d add the explorer as well:

Explorer

Screen Shot 2020-05-21 at 1.05.36 AM

Make sure you don’t have your Udim2’s mixed up. The GUI may already be in the position you specified.

Alternatively you can I believe put the tweenposition in a print and it returns true or false in accordance to whether the tween wil play.

1 Like

Yeah, they’re in the correct position. I ended up copying and pasting another function that did essentially the same thing to no avail, so I think something else is doing it. The game has a lot of loading and resetting the character is doing it.

local winf = false

You didn’t even set it as a bool in the first place im confused how that’d work

Yeah, JackOfAllTrades101 said to just declare it as false outside of the function. I think it was the resetting and stuff that caused it not to work, as I mentioned before.

Send your current full script here if you’ve made any changes

Updated script:
function win(winnername)
	warn("Function win")

	if not winf then
		winf = true
		local newpos = UDim2.new(0.5, 0, 0.5, 0)
		local oldpos = UDim2.new(0.5, 0, 2, 0)
		
		script.Parent.Parent:TweenPosition(newpos, Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 0.5) 
		
		wait(.1)
		
		-- Roblox services
		local ReplicatedStorage = game:GetService("ReplicatedStorage")
		 
		-- Require module
		local TypeWriter = require(ReplicatedStorage:WaitForChild("TypeWriter"))
		TypeWriter.typeWrite(script.Parent, "Game over! "..winnername[1].." has won the game!")
		wait(2)
		script.Parent.Parent:TweenPosition(oldpos, Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 0.5)
		
		script.Parent.Text = "Waiting for map..."
	else 
		return
	end
	
end

game.Workspace.Maps.ChildAdded:Connect(textadd)


local ReplicatedStorage = game:GetService("ReplicatedStorage")
local newPlayerEvent = ReplicatedStorage:WaitForChild("EliminatedPlayer")
local gameEnd = game.ReplicatedStorage.WinnerPopup

gameEnd.OnClientEvent:Connect(win)

newPlayerEvent.OnClientEvent:Connect(plrrmv)

winf = false

I think I’m getting onto something though as it’s tweening properly, it’s just the text that isn’t displaying.

Yeah, I got it to work. The issue was that I was doing Player:LoadCharacter() before the GUI tweened, causing the issue. Thank you, as well as @JackOfAllTrades101 for helping! It’s greatly appreciated.

2 Likes