Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would I make a GUI tween after a player Respawns?

Hello,

I am working on game by myself where I learn to script a lot better than with help.

So In the game, I want a GUI to tween in a few seconds after respawn. How would I do it? The way I used to do it was by, when they select the team, I would do :BreakJoints and then clone the GUI to starterGui. AFter doing that, I hadn't used studio for ages and so many changes have occured, it's so hard for me to adapt.

Now, that method doesn't work from my old game that I made, I had to improvise.

I can do the tweening bit using :TweenPosition(UDIm2.new(0,0,0,0) but I am not sure how I could do it AFTER a player has respawned, after death/reset, not when they join the game.

But how can I tell the GUI to only start tweening after the player has respawned. I don't want it to tween when they join the game, because I have other GUIs what are in place to help them to select their team.

Is there a function or something that I would say like OnRespawn to help the script know when to tween the gui. Or is it another way which I couldn't have thought of.

I just need the function or whatever to tell the script to tween the gui, i can do the rest of it myself, I think.

Thanks, TonyV

1 answer

✓ Accepted answer

Here is what I came up with, you should put this under StarterPlayer > StarterPlayerScripts.

I'm not sure if this is the best way to do it, but this is what I got.

local Player = game.Players.LocalPlayer
local FirstCharacter = true

Player.CharacterAdded:Connect(function(Character)
	print("Character added.")
	if FirstCharacter then --Just joined.
		FirstCharacter = false --For next time they spawn.
	else --Respawned
		print("Respawned!") --Put tweening here. Use Player.PlayerGui to get into the GUIs.
	end
end)

EDIT: To make it check a player's team, you can do the following code to check their team before tweening the UI:

local Player = game.Players.LocalPlayer
local FirstCharacter = true
local Teams = game:GetService("Teams")
local Team = Teams:FindFirstChild("TeamName")

Player.CharacterAdded:Connect(function(Character)
	print("Character added.")
	if FirstCharacter then --Just joined.
		FirstCharacter = false --For next time they spawn.
	elseif Player.Team == Team then --Respawned and is on team.
		print("Respawned!") --Put tweening here. Use Player.PlayerGui to get into the GUIs.
	end
end)

7 comments

0

Thanks a alot. I'll try now and if it works, I'll accept!

0

Can I ask, if I wanted to check the players team before tweening it, how would i go about doing this. Would i do if player.Team == 'oof' then (insert tweening)

0

I have updated the post for that.

0

I keep getting the output as PlayerGui is not a member of Player. This is from the part where I defined the frame that I want tweened. I put local gui = game.Players.LocalPlayer.PlayerGui.ScreenGui.ssa as the definition. 

0

Make sure that this is a LocalScript and not a Script.

0

You should also define this after they are spawned again.

0

yep, i just did that and it worked. Thanks alot!

This discussion is preserved as it was. New answers, comments, and votes are closed.