This Script is located in game.ServerScriptService
game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder", player) leaderstats.Name = "leaderstats" local Cash = Instance.new("IntValue", leaderstats) Cash.Name = "Cash" end) game.ReplicatedStorage.CashClickerEvent.OnServerEvent:Connect(function(player) player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 1 end)
The second script to trigger the RemoteEvent is located in game.Workspace
local remoteEvent = game.ReplicatedStorage:WaitForChild("CashClickerEvent") local ClickDetector = game.Workspace.Part.ClickDetector ClickDetector.MouseClick:Connect(function() remoteEvent:FireServer() end)
ServerScriptService
game.ReplicatedStorage.CashClickerEvent.OnServerEvent:Connect(function(player, Click) if Click == "Fire" then player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 1 end end)
Second script
ClickDetector.MouseClick:Connect(function() remoteEvent:FireServer("Fire") end)
local Players = game:GetService("Players") -- [[Server Script]] Players.PlayerAdded:Connect(function(plr) local leaderstats = Instance.new("Folder", plr) leaderstats.Name = "leaderstats" local Cash = Instance.new("IntValue", leaderstats) Cash.Name = "Cash" end) workspace.Part.ClickDetector.MouseClick:Connect(function(plr) -- Can be used on Server. WILL WORK! Doesnt need to be in second script, Players.PlayerAdded wont yield, Players.PlayerAdded and ClickDetector.MouseClick is a RBXScriptSignal. plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value + 1 end)