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

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

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)

7 comments

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.

0

I don't think you can detect a player through clickdetector. Correct me if I'm wrong.

0

Meltdown, then you are completely wrong. MouseClick returns the player who clicked it.

0

Hmm, I was absolutely certain that ClickDetector MouseClick did not return anything. Did Roblox change it recently?

0

First of all, it's an argument, not a return value. Secondly, it always has.

0

No, MouseClick is an event which returns player. Not a function.

0

@Link150 had the answer. All i had to do was change it to a localscript and it worked. Thanks for answering anyways guys!

1 answer

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.

1 comment

0

Can you make it work with module script?

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