It cant teleports. Output is "couldnt find player"
game.Players.PlayerAdded:Connect(function(plr) plyr = script.Parent game.ReplicatedStorage.teleport.OnServerEvent:Connect(function() if plyr ~= nil then if plyr.WaitForChild("HumanoidRootPart") ~=nil then plyr.WaitForChild("HumanoidRootPart").CFrame = CFrame.new(16.5, 5.5, -11.5) print("humanoidrootpart is found") else print("couldnt find humanoidrootpart") return end else print("couldnt find player") end end) end)
Why are you connecting a PlayerAdded
event to a .OnServerEvent
? .OnServerEvent
passes the Player instance as the first parameter, so don't throw it away.
WaitForChild
yields (makes the script wait) until it can find that instance it was waiting for. WaitForChild
DOES NOT return a value, unlike FindFirstChild
which returns nil if it can't find that instance, but WaitForChild is fine for this.
game:GetService("ReplicatedStorage").teleport.OnServerEvent:Connect(function(Player) Player.Character:WaitForChild("HumanoidRootPart").CFrame = CFrame.new(16.5, 5.5, -11.5) print("humanoidrootpart is found") end)
WaitForChild is not indexed but is a function (sort of, i think) so you should use it with a colon.