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

Teleporting Players on Spawn?

So, I wanted to be able to spawn a player in a custom location without having to use a spawn part. So I tried to make it so that when your character spawns in you are teleported to a specefic CFrame. Which I did so using this:

game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(character)
		local humanoid = character:FindFirstChild("Humanoid")
		character.Torso.CFrame=CFrame.new(0,50,0)+findBaseOf(player).Position
		if humanoid then
			humanoid.Died:connect(function()
				wait(2)
				character:Destroy()
				wait(1)
				player:LoadCharacter()
			end)
		end
	end)
	player:LoadCharacter()
end)

After trying that I got an error saying "attempt to index a nil value". So I figured the torso hadn't loaded into the character yet and I replaced the teleporting line(The line with the error) with this:

character:WaitForChild("Torso").CFrame=CFrame.new(0,50,0)+findBaseOf(player).Position

This however did not help and it still returned the same message. So my question is, how do you go about spawning players into a specific location or teleporting them when they spawn without getting that error?

7 comments

0

Please define what findBaseof is.

0

All you need to know is that it returns a part that is in workspace.

0

can you post the full error message? There should be a line on which the error was encountered..

0

11:49:27.942 - Workspace.PlayerHandler:33: attempt to index a nil value

0

I don't see how that helped though ImageLabel

0

Well line 33 is obviously not in the snippet you've provided so let us know exactly what the equivalent of line 33 is ....

0

Line 33 is in the snippet ... It's just not labeled as line 33. In the original question I said "I replaced the teleporting line(The line with the error)" though ...

2 answers

It looks to me like either the function "findBaseOf()" is returning nil or the ".Position" value, of whatever "findBaseOf()" is returning, is nil. I could give better input if you told me exactly what "findBaseOf()" is and what it consists of. I have to give this comment as an answer because I can't comment on any of the posts.

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