Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Attempt to index number with 'Character'?

Asked by
DevRhy 0
4 years ago

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)
0
try removing :wait() as it might think that you intend for that to be "char"'s value WideSteal321 773 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.

0
localplayer?? CaioAlpaca 342 — 4y
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. xInfinityBear 1777 — 4y
Ad

Answer this question