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

Attempt to index number with 'Character'?

Not entirely sure what is going on here but I get this error.

Players.DevRhy.PlayerGui.ScreenGui.TextButton.Script:15: attempt to index number with 'Character'

my script is:

function part(head)
		local X = head.Position.X
		local Y = head.Position.Y
		local Z = head.Position.Z
		
		local posAboveHead = Vector3.new(X, Y + 5, Z)
		local part = Instance.new("Part")
		part.Parent = workspace
		part.Position = posAboveHead
end



script.Parent.MouseButton1Up:Connect(function(plr)
	local char = plr.Character or plr.CharacterAdded:wait()
	
	local head = char.Head
	
	part(head)
	
end)

1 comment

0

try removing :wait() as it might think that you intend for that to be "char"'s value

1 answer

The MouseButton1Up event doesn't return the player that clicked it. It returns the mouse's x and y screen coordinates.

I'd recommend using a local script and fire a Remote Event if needed. Or, if you don't want to use Remote Events for some reason, you could use script.Parent's in a server script until you reach the player.

2 comments

0

localplayer??

0

I mean, I'm pretty sure he wants this server sided. If not, then yes, you can use local player in a local script.

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