✓ Accepted answer
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
local RemoteName = "hi"
local RS = game:GetService("ReplicatedStorage")
local ScreenGui = script.Parent
local TextButton = script.Parent.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)
1 comment
http://idownvotedbecau.se/itsnotworking