The issue at hand
The issue here is that you are trying to change values that do not permit the client to them them, on the client. This Client , Server separation is what is known as Filtering Enabled and is forced upon all roblox games. It exists as a security measure to prevent exploiters and "hackers"
Filtering Enabled
Filtering Enabled, or Network Filtering, or FE prevents the client or player from accessing items in Server Storage and Server Script Service. And also prevents the server from accessing anything in a player's PlayerGui. Of course, replicated storage exists as a way to store things both the client and server are supposed to see, such as remote events and remote functions
Remotes
Currently, two of the main ways of Client-Server communication are the remote function and the remote event. A remote event has three functions and two events, those being :FireServer(), :FireClient(), :FireAllClients(),OnServerEvent() and OnClientEvent respectively. The FireServer function and OnServerEvent event are used for Client to server communication while FirClient, FireAllClients, and OnClientEvent are used for Server to client communications
Remote functions are a bit more complicating to some people, as they only have 2 functions and 2 callbacks, those being :InvokeServer, :InvokeClient,OnServerInvoke and OnClientInvoke
invokeServer and OnServerInvoke are used for Client to server communications while InvokeClient and OnClientInvoke are used for Server to Client communications
A couple of other things to note, the FireClient and InvokeClient functions require a player parameter , which OnServerEvent and OnServerInvoke has "built in" player arguments, so sending the player object over isn't necessary, nor advised
Examples
local remote = game.ReplicatedStorage.RE
remote:FireServer("woo", "khanovich", "builderman")
remote.OnClientEvent:Connect(function(...)
print(...)
end)
local remote = game.ReplicatedStorage.RE
remote.OnServerEvent:Connect(function(plr,...)
print(plr.Name.." sent:",...)
remote:FireClient(plr,"oof","ree","ding")
end)
and
local remote = game.ReplicatedStorage.RF
local name = remote:InvokeServer("Cheese")
print(name)
local remote = game.ReplicatedStorage.RF
remote.OnServerInvoke = function(plr,thing)
print(plr.Name.."_"..thing)
end)
Fixing the issue
With the basics laid out, let's get to fixing your script(s)
A couple of things that you do wrong,
1: using a value instead of reference for cash check out Incapaxion's answer here
2:Not making your script FE friendly,
3.not using waitForChild on something instanced after the game starts
with all said, here it is:
local tool = script.Parent
local plr = game.Players.LocalPlayer
local ls = plr:WaitForChild("leaderstats")
local re = game.ReplicatedStorage.RemoteEvent
function onActivation()
re:FireServer("IncreaseMoney")
end
tool.Activated:Connect(onActivation)
local re = game.ReplicatedStorage.RemoteEvent
re.OnServerEvent:Connect(function(plr,action)
if action == "IncreaseMoney" then
plr.leaderstats.Money.Value = plr.leaderstats.Money.Value + 1
end
end)
Hopefully this helped you along, and have a wonderful day
1 comment
This is a borderline request, so im not gonna type it out. But the issue you're having is FE, you need to use a remote event to change the cash value. This is a very common issue and should be easy to find the answer with the search feature.