Gui Tween Doesn't Play

Hey Guys. I’m currently trying to get this tween to work where the PortalGuiFrame fades in and then out after entering a portal. For some reason the Tween does not play, and I already checked if the remote event actually works and it does. I’ve tried looking up tutorials to see if I was doing anything wrong but I couldn’t find anything in my code that would make the tween not play. Thanks for the help!

PortalGuiHandle LocalScript

local TweenService = game:GetService("TweenService")

local PortalRemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvents"):WaitForChild("Portal")
local PortalGuiFrame = script.Parent

local tweenInfo = TweenInfo.new(
	2,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.InOut,
	0,
	true
)

local tween = TweenService:Create(PortalGuiFrame, tweenInfo, {BackgroundTransparency = 0})

PortalRemoteEvent.OnClientEvent:Connect(function()
	
	print("Activated")
	
	PortalGuiFrame.Visible = true
	
	tween:Play()
	
	PortalGuiFrame.Visible = false
	
end)

What triggers the portal remote event?

object.Touched:Connect(function(hit)
					if hit.Parent:FindFirstChild("Humanoid") and hit:IsA("Part") then
						
						if PortalDebounce == false then
							
							PortalDebounce = true
							
							local char = hit.Parent
							local humanoid = char:WaitForChild("Humanoid")
							local humanoidRoot = char:WaitForChild("HumanoidRootPart")
							local plr = Players:GetPlayerFromCharacter(char)
							
							
							PortalRemoteEvent:FireClient(plr)
							
							--Waits until screen is fully covered by effect
							wait(1)
					
							humanoidRoot.CFrame = lobby:WaitForChild("Baseplate").CFrame * CFrame.new(0, 7, 0)
					
							--Make sure to add to the player's wins!!!
							
							wait(1.5)
							PortalDebounce = false
							
						end
					
					end
					
				end)

Just so you know the variable object is the part of the portal you enter

I’m currently in studio trying to test your code and fix it, I’ll reply back when its fixed

1 Like

I’m not a scripter, but I think the comma broke it. Remove the comma in tweenInfo

Without the comma, the code would error. It is needed

1 Like

I think the tween is playing but it is immediately being changed to invisible, try adding a wait in between the tween and “PortalGuiFrame.Visible = false”

Ediit: Just tested this myself thats not the reason, but why did you set reverse in the tweeninfo to true?

You directly calling PortalGuiFrame.Visible = false before the tween even finished just put tween.Completed:Wait() between tween:Play() and PortalGuiFrame.Visible = false which will look like this

local TweenService = game:GetService("TweenService")

local PortalRemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvents"):WaitForChild("Portal")
local PortalGuiFrame = script.Parent

local tweenInfo = TweenInfo.new(
	2,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.InOut,
	0,
	true
)

local tween = TweenService:Create(PortalGuiFrame, tweenInfo, {BackgroundTransparency = 0})

PortalRemoteEvent.OnClientEvent:Connect(function()
	
	print("Activated")
	
	PortalGuiFrame.Visible = true
	
	tween:Play()
	tween.Completed:Wait()
	PortalGuiFrame.Visible = false
	
end)
	PortalGuiFrame.Visible = true
	
	tween:Play()
	
	PortalGuiFrame.Visible = false

As far as I’m aware, tween’s don’t halt the thread. So you’re immediately setting Visible to false.

Alright the code works, thanks for the help

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.