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

Character Auto Teleport to location when reset?

Just need the character to teleport to a bricks location when they reset. I have a team changing script all functional but when the player resets I need them to teleport to their teams area. This is what I got yet nothing happens? No output errors just nothing at all.

local player = game.Players.LocalPlayer
local character = player.Character
local teles = workspace.Teams
if not character or not character.Parent then
	    character = player.CharacterAdded:wait()
		if player.TeamColor == "Black" then
			character.Torso.CFrame = CFrame.new(teles.Imptel.Position)
		elseif player.TeamColor == "Forest green" then
			character.Torso.CFrame = CFrame.new(teles.RebTele.Position)
	end
end

Any help would be greatly appreciated. It's a LocalScript in the PlayerGui.

2 comments

0

first off all use the died function then use the teleport script, that should start u off

0

first off all use the died function then use the teleport script, that should start u off

1 answer

✓ Accepted answer

The main problem is that you are only teleporting the player if the character does not exist at the time the script runs - instead, you can just fix the problem you are trying to solve in one line:

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Teles = workspace.Teams

-->> Teleport

Here's what your code would like if I only fixed the problem so you understand exactly what the problem was:

local player = game.Players.LocalPlayer
local character = player.Character
local teles = workspace.Teams

if not character or not character.Parent then
        character = player.CharacterAdded:wait()
end

--> I took this part out of the if statement above
if player.TeamColor == "Black" then
         character.Torso.CFrame = CFrame.new(teles.Imptel.Position)
elseif player.TeamColor == "Forest green" then
         character.Torso.CFrame = CFrame.new(teles.RebTele.Position)
end

Also, I recommend you do all of this on the server, not the client. It will not work with FE (or without the soon-to-be Experimental mode).

local Teles = workspace.Teams

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		-->> Teleport
	end)
end)

Finally, a tip: Use Tab to format your code, not space. Space is inconsistent and really annoying to use, it is much easier to use tab.

if Condition then
	print() -- using tab, 1 character
    print() -- using space, 4 characters
end

Hope I helped!

~TDP

1 comment

0

Awesome thank you!

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