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

Teleport HumanoidRootPart.CFrame with server script?

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)

1 answer

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.

2 comments

0

Big thanks. Im newbie on LUA and this is help me for my skills

0

You're welcome, please mark as an answer if it helped.

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