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

How to use RemoteEvents for buying items?

My RemoteEvent does not seem to want to work the way I intended. I need the starterGUI shop button to fire an event that removes Cash from the player's leaderstats and gives them an item but I can't seem to get the Cash value to decrease. Also my prints in the actual event are not showing up in the console. What is missing here?

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local SwordEvent = ReplicatedStorage:WaitForChild("SwordEvent")

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function(player)
	SwordEvent:FireServer()
	print("Sword Purchase Requested")
	end)

This is the local script on the Sword button within starterGUI shop. This works as far as I can tell but maybe something here is happening?

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local SwordEvent = ReplicatedStorage:WaitForChild("SwordEvent")

local function onSwordPurchase(player)
	print("Trying now...")
	if player.leaderstats.Cash.Value >= 100 then
		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - 100
		print("Bought a Sword")
	end
end

This is the actual event. There is no actual sword object yet, I am just trying to figure out why the Cash value will not change and why the prints will not print.

1 comment

0

OnServerEvent

1 answer

✓ Accepted answer

i think you are missing one line at the end of your serverscript...

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local SwordEvent = ReplicatedStorage:WaitForChild("SwordEvent")

local function onSwordPurchase(player)
	print("Trying now...")
	if player.leaderstats.Cash.Value >= 100 then
		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - 100
		print("Bought a Sword")
	end
end

SwordEvent.OnServerEvent:Connect(onSwordPurchase) -- this line here

1 comment

0

thank you I feel like an idiot. I forgot the thing that actually connected it.

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