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

How do I make a button only fire when you have a certain amount of value?

Asked by
M3N0Hax -7
5 years ago

I am currently working on a game called "Pet Rock Sim" and I am looking into making a shop to buy your pets.The way you buy a pet is simply click on a dedicated button for it, but I don't know how to make that button only fire when you have a certain amount of cash.

1 answer

Log in to vote
0
Answered by 5 years ago

Add the RemoteEvent to the ReplicateStorage.

-- Script

--// Variables
local RemoteEvent = game.ReplicatedStorage:WaitForChild("RemoteEvent")

--// Remote Event
RemoteEvent.OnServerEvent:Connect(function(plr, Price)
    if plr and Price then
        local Points = plr:FindFirstChild("leaderstats"):FindFirstChild("Points").Value
        if Points then
            if Points >= Price then
                plr:FindFirstChild("leaderstats"):FindFirstChild("Points").Value = plr:FindFirstChild("leaderstats"):FindFirstChild("Points").Value - Price
                print(Points)
                print(Price)
                RemoteEvent:FireClient(plr)
            end
        end
    end
end)

-- Local Script

--// Variables
local RemoteEvent = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local Button = script.Parent:WaitForChild("TextButton")

--// Settings
local Price = 100
local plr = game.Players.LocalPlayer

--// Button Event
Button.MouseButton1Click:Connect(function()
    RemoteEvent:FireServer(Price)
end)

--// RemoteEvent
RemoteEvent.OnClientEvent:Connect(function(plr)
    print("Successfully")
end)
Ad

Answer this question