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

Script seems to finish before doing what I need it to? Teleporting players on respawn

So I recently posted here, got a lot of help and some tips to make my script function with FE. Yet it still does not work. It is now a Script in the Workspace. No output errors either here it is:

local Teles = workspace.Teams

game.Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Character)
		Character.Humanoid.Died:connect(function(c)
			print("worked")
			if Player.Team == "Imperials" then
				Character.Torso.CFrame = CFrame.new(Teles.ImpTel.Position)
			elseif Player.Team == "Rebels" then
				Character.Torso.CFrame = CFrame.new(Teles.RebTele.Position)
			end
			print("done")
		end)
    end)
end)

So basically what happens in as soon as the player resets(which is fine, exactly when I need it to fire) it instantly prints both of those print statements at lines 6 and 12. Seems to skip over the if's. The prints happen as soon(practically instantly) as the player dies so I dont think it can really teleport the player if the script ends before the player has even respawned. I have no guess as to how I am supposed to fix this any help? Anything is appreciated!

1 comment

0

Add a wait. Code always runs as fast as it can.

2 answers

Try using TeamColor instead like this(I'm using really black as Imperials color and rebels as crimson just for an example but replace the colors with the team colors you have!)

local Teles = workspace.Teams

game.Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Character)
        Character.Humanoid.Died:connect(function(c)
            print("worked")
            if Player.TeamColor == BrickColor.new("Really black") then
                Character.Torso.CFrame = CFrame.new(Teles.ImpTel.Position)
            elseif Player.TeamColor == BrickColor.new("Crimson") then
                Character.Torso.CFrame = CFrame.new(Teles.RebTele.Position)
            end
            print("done")
        end)
    end)
end)

Your problem is that you're trying to compare Team objects with Strings. The if statements aren't being skipped, they simply never become true. You need to compare Player.Team with the Team objects in game.Teams.

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