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

Teleporting a Player When They Spawn?

I'm trying to make it so the player teleports once they've spawned it, however it isn't working. It says player isn't a valid member of workspace.

local Players = game:GetService("Players")

function onPlayerAdded(player)
	print(player.Name .. " has entered the game")
	player.CharacterAdded:connect(function(character)
	local humanoid = character:FindFirstChild("Humanoid")
	humanoid.WalkSpeed = 0
	workspace:findFirstChild("Player")
	game.Workspace.Player.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(0, 50, 0))
	end)
	end


Players.PlayerAdded:connect(onPlayerAdded)

for _,player in pairs(Players:GetPlayers()) do
     onPlayerAdded(player)
end

1 comment

0

Line 8 doesn't make sense. you're trying to find something called "Player". You probably just want to use Character.HumanoidRootPart.CFrame on line 9.

2 answers

You used Vector3.new and not CFrame.new. Maybe that's the issue?

I looked through your script, and I resolved your error.

local Players = game:GetService("Players")

function onPlayerAdded(player)
    print(player.Name .. " has entered the game")
    player.CharacterAdded:connect(function(character)
  	  local humanoid = character:FindFirstChild("Humanoid")
  	  humanoid.WalkSpeed = 0
  	  character.HumanoidRootPart.CFrame = CFrame.new(0, 50, 0) --At the beggining, put "Character" instead of "workspace.Player". Also, consider using just CFrame then using Vector3.
    end)
end


Players.PlayerAdded:connect(onPlayerAdded)

for _,player in pairs(Players:GetPlayers()) do
     onPlayerAdded(player)
end

Hope this works!

1 comment

0

That didn't seem to work, however the output doesn't show any errors.

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