Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Shop events aren't working?

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

✓ Accepted answer

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.

2 comments

0

I should considered to make a shop since shop questions get questioned alot.

0

I was using a bindable event before haha. Thanks for that!

This discussion is preserved as it was. New answers, comments, and votes are closed.