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

Attempt to index local "player" a number value?

Asked by 8 years ago

I do not know why it is saying that this is a number value I need help figuring this out and if you can answer it and explain what I did wrong so I can learn I would be thankful. I also have provided some pictures. (It is in a LocalScript)

local Player = game:GetService("Players").LocalPlayer

function yes(Player)
    Player.leaderstats.WantedLevel.Value = Player.leaderstats.WantedLevel.Value + 1
    Player.Character.Rank.Frame.Name1.Text.Value= Player.Name.."- Robbing"
    local h = script.Parent.Parent
    h.Visible = false
    script.Parent.Parent.Parent.OneThousand.Visible = true
    local rob = script.Parent.Parent.Parent.RobbingPresent
    rob.Script.Disabled = false
    end
end

script.Parent.MouseButton1Down:connect(yes)

Error Picture: https://gyazo.com/3caada18d8f35eab07f19737c850cfd8

Explorer Picture: https://gyazo.com/2c644b00f8f522ab8eafe79c047cff41

Thank you for taking a look guys!

3 answers

Log in to vote
1
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
8 years ago

Problem

You're changing the Player variable in the event to a number value. MouseButton1Click does not return the player who clicked on the button. Since MouseButton1Click is used in Guis often times held in PlayerGui it is completely unnecessary for you to get a player variable in the event. Instead the event will provide the location of the mouse in the button at the time of the click.


Solution

Just remove the Player variable in the event. It is not necessary unless you want to do like animations, then I would just recommend renaming the variable to something else.


Final Script

local Player = game:GetService("Players").LocalPlayer

function yes()
    Player.leaderstats.WantedLevel.Value = Player.leaderstats.WantedLevel.Value + 1
    Player.Character.Rank.Frame.Name1.Text.Value= Player.Name.."- Robbing"
    local h = script.Parent.Parent
    h.Visible = false
    script.Parent.Parent.Parent.OneThousand.Visible = true
    local rob = script.Parent.Parent.Parent.RobbingPresent
    rob.Script.Disabled = false
    end
end

script.Parent.MouseButton1Down:connect(yes)

Just a heads up, this script is not FilteringEnabled compatible, so if you plan on using a similar script in a FilteringEnabled environment you will need to revamp the script.


Hopefully this answered your question, if so do not forget to hit the accept answer button. If you have any questions, feel free to comment below.
Ad
Log in to vote
1
Answered by
Link150 1355 Badge of Merit Moderation Voter
8 years ago

The problem is you are trying to access your local variable Player. However the 'Player' argument of your yes() function shadows it, which means your function cannot see your variable Player because the argument has the same name.

Now, for the reason the script errors "attempt to index a number value". The thing is the MouseButton1Down event passes two numbers as arguments to your yes function callback: the x and y coordinates of the click. So your Playerparameter gets assigned the 'x' coordinate and the 'y' coordinate is lost (because your function declaration does not specify enough arguments).

Remove "Player" from the list of arguments to yes and everything should be alright.

Log in to vote
0
Answered by 5 years ago

its more like this, and i have a same problem on my side. like a level of something get a number value back while i have a int. so maybe u need to change the int to numbervalue.

local function yes(player)

    player.leaderstats.WantedLevel.Value = Player.leaderstats.WantedLevel.Value + 1

    Player.Character.Rank.Frame.Name1.Text.Value = Player.Name.."- Robbing"

    local h = script.Parent.Parent

    h.Visible = false

    script.Parent.Parent.Parent.OneThousand.Visible = true

    local rob = script.Parent.Parent.Parent.RobbingPresent

    rob.Script.Disabled = false

end

script.Parent.MouseButton1Down:connect(player)
    yes(player)
end
0
big p from Player is small P in all then it should work or u have the wrong value item User#27824 0 — 5y
0
Found my error. Can say local item = blablabla. item.value and then say if item.value == 1 then...... need to take away the one dotvalue on one side. like local item = blabla.item and then if item.Value == 1 then.... or local item = blablabla.item.Value and then if item == 1 then...... on ure side its the player part between the () player clocks on mouse get in yes then find player. blablabla User#27824 0 — 5y

Answer this question