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

I can already tell there are a lot of errors with my script. Can someone help?

local tele = script.Parent.Teleporter
local player = game.Players.LocalPlayer
script.Parent.ClickDetector.MouseClick:Connect(function()
		   player.Character.HumanoidRootPart.CFrame = tele.CFrame * CFrame.new(0, 3, 0)
end)

The error says 'attempt to index nil with character.

2 answers

You can't get the local player from a server script. The MouseClick event has a parameter which is the player that clicked the ClickDetector so you can just get the player from there instead.

local tele = script.Parent.Teleporter
script.Parent.ClickDetector.MouseClick:Connect(function(Player)
	local Character = Player.Character
	local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
	HumanoidRootPart.CFrame = tele.CFrame * CFrame.new(0, 3, 0)
end)

attempt to index nil with character. means ru doing nil.Character means ur player is nil means that game.Players.LocalPlayer is nil which means ur doing it in a script and not in a localscript

how would a script know which player ur talking about is the Localplayer?

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