if player click button then +500cash - How to make it ? button = script.Parent
COMMUNITY QUESTION
if player click button then +500cash - How to make it ?
1 answer
If you wish to SAVE these stats, you must use a remote event to trigger the server to change them.
Local Script:
local Button = script.Parent
local Remote = Instance.new("RemoteEvent")
Remote.Parent = game:GetService("ReplicatedStorage")
Remote.Name = "AddMoney"
local function FireRemote()
Remote:FireServer()
end
local function DescAdded(Inst)
if Inst.Name == "Loaded" then
Button.MouseButton1Down:Connect(FireRemote)
end
end
Remote.DescendantAdded:Connect(DescAdded)
Server Script:
( PUT THIS IN SERVERSCRIPTSERVICE )
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MoneyRemote = ReplicatedStorage:WaitForChild("AddMoney")
local Loaded = Instance.new("BoolValue")
Loaded.Name = "Loaded"
Loaded.Parent = MoneyRemote
MoneyRemote.OnServerEvent:Connect(function(Player)
local MoneyValue = Player["leaderstats"]["YOURVALUENAME"] -- change to your money value name
MoneyValue.Value = MoneyValue.Value + 500
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.
