How do I make this tp script

So technically this script is supposed to make a screen fade on then make it tp you to a game. Instead it just freezes and crashes, why?
This is the script:

local function RunTP()
	while true do
	script.Parent.Parent.Parent.Parent.Blackout.Frame.BackgroundTransparency = script.Parent.Parent.Parent.Parent.Blackout.Frame.BackgroundTransparency + 0.2
		end
	end
script.Parent.MouseButton1Down:Connect(function()
	
		script.Parent.Parent.Parent.Parent.Blackout.Frame.ZIndex = 100
	script.Parent.Parent.Parent.Parent.Blackout.Frame.Visible = true
	RunTP()
		wait(0.5)
		script.Parent.Parent.Parent.Parent.Blackout.Frame.Teleporting.Visible = true
    	game:GetService("TeleportService"):Teleport(5356825192)
end)


If this script would work but theres an easier way, please tell me. All I need is a frame to fade on when you click a button and tp you to a game.

1 Like

The crash is coming from the second line, the while true do statement.

This is a loop, which means that it will run infinitely. So essentially what you’re doing is you are constantly making the transparency increase by 0.2. The reason this causes a crash is because it is being executed over and over again without yielding (pausing).

Amend it to this:

while script.Parent.Parent.Parent.Parent.Blackout.Frame.BackgroundTransparency < 1 do
     script.Parent.Parent.Parent.Parent.Blackout.Frame.BackgroundTransparency = script.Parent.Parent.Parent.Parent.Blackout.Frame.BackgroundTransparency + 0.2
     wait()
end

Hence it will only increase transparency until it is maxed, and it will leave a small gap between doing so.

If you want to slow down the fade, increase the number inside the “wait(x)”.

Hope this helps,
-Tom :slight_smile:

2 Likes

When you execute the RunTP function, it will run a while loop without a wait() and that causes the freeze and crash issue. But one more thing is that you can’t be TPed even if you add a wait() because while true loop loop forever so I would suggest tweening the frame or use a for loop.

2 Likes

How would I just make like the screen fall onto the screen (Sorry I am a beginner when it comes to this)
So like a black frame would like ‘fall’ or slide onto the screen

You can change while loop to for loop, and put wait.

You should look at this article: UI Animations | Documentation - Roblox Creator Hub
Also you should consult this piece of documentation: TweenService | Documentation - Roblox Creator Hub

This will allow you to understand and explore how UIs move across your screen in an effortless fashion. This is relatively advanced programming for Roblox, so if you can master this you’re well on your way to becoming an accomplished scripter :smiley:

Hope this helps,
-Tom :slight_smile:

1 Like

Thanks everyone :smiley:
I will mark this solved but feel free to comment because I would love to see peoples ideas!!

Reply: I got the tweening running! :slight_smile:

Hey, thanks alot! You really helped me out. I will not make the mistake again. Good luck with your games!!

Excellent news!

I hope you can experiment with tweening other things that aren’t UIs (such as brick transparency etc) that can make some really cool change sequences in your games in the future! It’s so powerful