To make the snow stat go up for the player name TheRobloxGamerYTy, you should do:
local Players = game:GetService("Players")
Players.TheRobloxGamerYTy.leaderstats.Snow.Value += 1
This will only add your value by once, and if the player isn't named TheRobloxGamerYTy, it won't make the snow stat goes up for him because the script above tries to make the player TheRobloxGamerYTy snow stat goes up but he isn't TheRobloxGamerYTy? Don't worry, and the script above obviously can't be the solution because it's not what we wanted:
Let's talk about how do you set up a brick that you can click it to make it do something:
Firstly, you add a pointy finger and it's named ClickDetector (Hopefully you know how, but if you don't, hover your mouse to the brick with your mouse in explorer, it will appear a plus (+) button, click it and search for something called ClickDetector and click the pointy finger icon or the text besides it. It will look like this).
If you understand what I mean, you must know how to do this step! The objective now is to add a script inside the ClickDetector, and edit the script and let it be:
local ClickDetector = script.Parent
local function DetectorClicked(PlayerWhoClicked)
PlayerWhoClicked.leaderstats.Snow.Value += 1
end
ClickDetector.MouseClick:Connect(DetectorClicked)
If you understand how the first example code I gave and the leaderstat script, you might understand what does this do or barely, let's explain how will it work
First, it will set up the MouseClick event and make it connect to DetectorClicked() event (or function, as you can see it besides the keyword DetectorClicked() in the code)
Second, we will need something called a "parameter", and the parameter in the DetectorClicked() event is PlayerWhoClicked, if you look at the script, you would find that PlayerWhoClicked is inside the () in the DetectorClicked() event, and that is a parameter, I won't explain more but what parameter does is give information as the parameter in the DetectorClicked() event will give the player that clicked the ClickDetector, also you can rename it something else you want but the information won't change
Lastly it gives the player who clicked one snow in the value
Why is this long? Because other tutorials I find is lame and just throw random professional words to you and want you to copy and paste their code (please don't, but this is really a tutorial so it's fine)
That's it, if you are confused then tell me below :lol:
2 comments
Also, anything that says "gold" has been changed to snow.
Yes, you named it "Snow", instead of "gold". Just name the local "Snow" to make it less confusing. I think you're following off a tutorial, which is fine..But you need to be careful with how you write code.