Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-2

im trying to like if you have 1 cash you can buy 1 ingridients please help me?

Asked by 5 years ago

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)

1 answer

Log in to vote
0
Answered by
NotedAPI 810 Moderation Voter
5 years ago

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)
0
I just cant seem to make it work can u add me and help me fix it? username: thecool_leoanrdokh thecool_leonardokh -2 — 5y
0
Do you have Discord? If so, what is it? NotedAPI 810 — 5y
0
LeoYT#9077 thecool_leonardokh -2 — 5y
0
Can I have some help again? thecool_leonardokh -2 — 3y
Ad

Answer this question