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!
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.
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.
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.
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 Player
parameter 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.
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