in my screen gui there is a button and in the button there is a local script
script.Parent.MouseButton1Click:Connect(function()
local plr = game.Players:GetPlayerFromCharacter(script.Parent.Parent) if plr.leaderstats.Cash >1 then plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value -1 plr.leaderstats.Ingridients.Value = plr.leaderstats.Ingridients.Value +1 end
end)
For one, you would need a RemoteEvent because if you just do it from that LocalScript it won't replicate to the server, which you want to happen.
Inside of ReplicatedStorage insert a RemoteEvent and name it whatever you want. You'll just have to put the name inside of the script below.
Inside of the LocalScript put this:
local player = game.Players.LocalPlayer -- Instead of doing script.Parent.Parent, you can do this. local RemoteName = "hi" -- Replace this with the name of your remote. local RS = game:GetService("ReplicatedStorage") local ScreenGui = script.Parent -- Change this to the path of your ScreenGui local TextButton = script.Parent.TextButton -- Change this to the path of your TextButton TextButton.MouseButton1Click:Connect(function() RS:WaitForChild(RemoteName):FireServer() end)
Once you've done that we need to make a Script inside of ServerScriptService. Once you insert one you can put the following code:
local RS = game:GetService("ReplicatedStorage") local RemoteName = "hi" RS:WaitForChild(RemoteName).OnServerEvent:Connect(function(player) if player:WaitForChild("leaderstats").Cash.Value >= 1 then player:WaitForChild("leaderstats").Cash.Value = player:WaitForChild("leaderstats").Cash.Value - 1 player:WaitForChild("leaderstats").Ingridients.Value = player:WaitForChild("leaderstats").Ingridients.Value + 1 end end)