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

I keep geeting an attempt to index error, please help?

I have this function that is supposed to set a players Magic value to a string, but it says player is a Number value.

function gameStart(player)
if player then
player.Stats.Magic = script.Parent.Parent.Parent.MagicFrame.Spinner.TextButton.Text
script.Parent.Parent.Parent.Parent:Destroy()
end
end

script.Parent.MouseButton1Down:connect(gameStart)

attempt to index local 'player' (a number value)

Please help!

5 comments

0

Hey connor, I was wondering if I could come and give your game a try?

0

Promise you wont steal the idea?

0

I promise. I'm already working on a game of my own. I can show it to you after if you want.

0

ok, ill open it up soon

1 answer

✓ Accepted answer

MouseButton1Down returns the mouse position.

Because when dealing with Player Guis you should always use a Local Script, we can get the player using Local Player.

local player = game.Players.LocalPlayer

function gameStart(mouse)
    player.Stats.Magic = script.Parent.Parent.Parent.MagicFrame.Spinner.TextButton.Text
    script.Parent.Parent.Parent.Parent:Destroy()
end

script.Parent.MouseButton1Down:connect(gameStart)

Good Luck!

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