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

Shop events aren't working?

Asked by 2 years ago

So, I need an event to trigger whenever someone clicks on a button to buy an item. But, for some reason, the event isn't working! Help me please.

script that triggers the event:

Price = 3
Item = "Burger"
be = game.workspace.Homes.Buy

script.Parent.MouseButton1Click:Connect(function()

    local player = game.Players.LocalPlayer
    local Cash = player.leaderstats.Gold
    if Cash.Value >= Price then

        Cash.Value = Cash.Value - Price


        be:Fire(Item, player)


    end
end)

script that holds the event:

RS = game:GetService("ReplicatedStorage")

local function onEvent(Item, player)
    print("the event fires at least...")
    local item = RS.Item
    local itemC = item:Clone()
    itemC.Parent = player.Backpack
    print("WE DID IT!")
end
be = game.Workspace.Homes.Buy
be.Event:Connect(onEvent)

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

First of all, you can only detect if a TextButton was clicked in a LocalScript. As soon as the client presses the Button, fire a RemoteEvent.

Now on a Script subtract the client's cash and add the item to the Backpack.

Notes:

  1. Doing the purchase on the client can lead to an exploiter making the purchase for free.

  2. Don't pass the price of the item in the RemoteEvent I'm pretty sure an exploiter can change the price.

There's no code because I don't want to create a shop right now since it can be time-consuming. I know this is not an answer but it should definitely help you.

0
I should considered to make a shop since shop questions get questioned alot. MarkedTomato 810 — 2y
0
I was using a bindable event before haha. Thanks for that! zaqree512345 3 — 2y
Ad

Answer this question