ERROR: attempt to index nil with 'Character'

im trying to make a textbutton teleport to a parts position when the button is clicked ! any help is appreciated

local Button = script.Parent
local tproadz = game.Workspace:WaitForChild("tproads")
Button.MouseButton1Click:Connect(function(Player) -- this is where the error is
	Player.Character:SetPrimaryPartCFrame(CFrame.new(tproadz.Position))
end)

I believe you are attempting to move the part on the client. You need to use a remote event and move the part on the server.

1 Like

The MouseButton1Click event does not give you the Player who clicked on the UI. To get the Player, this must be ran inside of a LocalScript, where you would get the player using game.Players.LocalPlayer.

3 Likes

NO im sorry to be not clear im trying to teleport the player who clicked the Button to the parts position where the part is named “tproads”

oh, if i run it in a local script wouldn’t it glitch other people seeing the player who teleported and making them invisible?

The Client can teleport the Character anywhere it wants to since it has NetworkOwnership over it. This change will appear to all other players in the game.

2 Likes

You’re right!
I never even realized that. I’ve been teleporting on the server.

Alright yeah, the only problem then is that you cannot get ‘Player’ from
Button.MouseButton1Click:Connect(function(Player)

You need to get the localPlayer like so:
local Player = game.Players.LocalPlayer

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.