Your title is a little misleading, it should be a once sentence explanation of your issue, in question format.
That aside...
Values and references
You are assuming that money and dirt are references to the Value property. This is not the case. When the Value property changes, money or dirt will not change, and if you change money or dirt, the Value will not update accordingly.
What you must do is just make money and dirt refer to their IntValue/NumberValue object directly, and directly access the Value property.
References
It is important to know the difference between a value and a reference.
You can think of references as holding some memory location.
In Lua, for example, functions are passed by reference.
Here is some code to demonstrate this:
local fn1, fn2, fn1ref;
fn1 = function()
for i = 1, 12 do
print(i^(1/3));
end
end
fn2 = function()
for i = 1, 12 do
print(i^(1/3));
end
end
fn1ref = fn1;
print(fn1 == fn1ref, rawequal(fn1, fn1ref));
print(fn1 == fn2, rawequal(fn1, fn2));
fn1 and fn1ref contain the same exact function in memory. fn2 is different despite the code, line count, ect, being the same.
Values
Datatypes such as booleans and strings for example, are passed by value, and here is some code to demonstrate how this works:
local bool = false;
local bool2 = bool;
bool = true;
print(bool, bool2);
The variables have different memory allocation, and thus the modification of bool did not modify bool2.
Applying this knowledge into your code, and more
onClicked looks like a good variable name to use for a function, yet this is not the case. onClicked is actually the 2D X axis of your mouse. The arguments passed to your MouseButton1Down listener are actually the 2D X and Y axes. This is misleading. You aren't even using onClicked.
Let's clean that portion up.
It might also be a good idea to handle this server side. Doing this client side means it will not replicate.
On the server side, you want to create a RemoteEvent, name it something like addMoney, place it in ReplicatedStorage, so the server and client can see it. Remotes allow for client <-> server communication. If you do not understand remote events, I gave an explanation on RemoteEvents here.
local remoteEvent = Instance.new("RemoteEvent");
remoteEvent.Name = "addMoney";
remoteEvent.Parent = game:GetService("ReplicatedStorage");
remoteEvent.OnServerEvent:Connect(function(client, ...)
local money, dirt = client.leaderstats.Money, client.playerstats.Dirt;
money.Value = money.Value + dirt.Value;
dirt.Value = 0;
end);
And on the client side, you simply call :FireServer:
local ReplicatedStorage = game:GetService("ReplicatedStorage");
button.Activated:Connect(function()
ReplicatedStorage.addMoney:FireServer();
end);
And that is it! It works server side now.
1 comment
If you do want to make a cool shop gui though, I recommend reading this: https://developer.roblox.com/articles/GUI-Animations and also the related articles you can find below it.