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

How can I add points to the leaderstats on the leaderboard through a ClickDetector?

Asked by 7 years ago

So I'm trying to make a script that adds a point to the leaderstats on the leaderboard with a ClickDetector. The problem is that it does not find the leaderstats in the LocalPlayer for some reason (as seen in the error I got:'leaderstats is not a valid member of Player'). How can I fix this so it adds a point to the leaderboard when you pick up the object? Thanks for the help!

(NOTE: This is a LocalScript that is ran under a ClickDetector inside a Union)

Here is the script:

local MeatValue = game.Players.LocalPlayer.leaderstats.Meat.Value

function GiveMeat()
    MeatValue = MeatValue + 1
    script.Parent.Parent:Remove()
end

script.Parent.MouseClick:connect(GiveMeat)
3
Don't use a LocalScript; Use a regular Script. The player who clicked will be automatically passed as first argument to your 'GiveMeat' function by Roblox. Link150 1355 — 7y
0
I don't think you can detect a player through clickdetector. Correct me if I'm wrong. Meltdown81 309 — 7y
0
Meltdown, then you are completely wrong. MouseClick returns the player who clicked it. MrLonely1221 701 — 7y
0
Hmm, I was absolutely certain that ClickDetector MouseClick did not return anything. Did Roblox change it recently? cabbler 1942 — 7y
View all comments (3 more)
0
First of all, it's an argument, not a return value. Secondly, it always has. Link150 1355 — 7y
0
No, MouseClick is an event which returns player. Not a function. cabbler 1942 — 7y
0
@Link150 had the answer. All i had to do was change it to a localscript and it worked. Thanks for answering anyways guys! ragingskull182 67 — 7y

1 answer

Log in to vote
3
Answered by 7 years ago
Edited 7 years ago

All of the information that is here from others is incorrect if you look at the ClickDetector Wiki if you scroll down to the events and look at MouseClick,you will see that it says that it returns the player who clicked it.

All you would need to change in your code:

function GiveMeat(player)
    local MeatValue = player.leaderstats.Meat.Value;
    MeatValue = MeatValue + 1;
    script.Parent.Parent:Destroy(); -- Remove is deprecated
end;

script.Parent.MouseClick:connect(GiveMeat);

** This should also be in a regular script **

I hope this helps! If it does please accept this as the answer. If it didn't help feel free to ask for more help with it, or if you have any other questions just ask.

0
Can you make it work with module script? PoometryPython -5 — 5y
Ad

Answer this question