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

How to use RemoteEvents for buying items?

Asked by 3 years ago

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.

0
OnServerEvent greatneil80 2647 — 3y

1 answer

Log in to vote
0
Answered by
NGC4637 602 Moderation Voter
3 years ago
Edited 3 years ago

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
0
thank you I feel like an idiot. I forgot the thing that actually connected it. DaGlizzzzzzyyyy 34 — 3y
Ad

Answer this question