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

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

Asked by 8 years ago
Edited 8 years ago

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!

0
Hey connor, I was wondering if I could come and give your game a try? MrLonely1221 701 — 8y
0
Promise you wont steal the idea? connor12260311 383 — 8y
0
I promise. I'm already working on a game of my own. I can show it to you after if you want. MrLonely1221 701 — 8y
0
ok, ill open it up soon connor12260311 383 — 8y

1 answer

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

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!

Ad

Answer this question