I have a problem with my buy system in my game. To buy an item the player must interact with a proximity prompt, here’s the script
local pp = script.Parent
local repstorage = game:GetService("ReplicatedStorage")
local remotes = repstorage.Remotes
pp.Triggered:Connect(function(player)
remotes.Buy1:FireClient(player)
end)
The script fires a remote event ( in repstorage ) which then in another script ( in serverscript service ), the script creates a function for buying the item. here’s the script :
local repstorage = game:GetService("ReplicatedStorage")
local remotes = repstorage:FindFirstChild("Remotes")
local serverscriptservice = game:GetService("ServerScriptService")
local reEating = remotes.Eating
local PlayerData = require((serverscriptservice.PlayerData.Manager))
local function eatmoney(player: Player)
PlayerData.AdjustMoney(player, 1)
end
local function buy1(player: Player)
PlayerData.AdjustMoney(player, -10)
end
reEating.OnServerEvent:Connect(eatmoney)
remotes.Buy1.OnServerEvent:Connect(buy1)
and
local Manager = {}
Manager.Profiles = {} --profile, storing data
function Manager.AdjustMoney(player: Player, amount: number)
local profile = Manager.Profiles[player]
if not profile then return end
profile.Data.Money += amount
player.leaderstats.Money.Value = profile.Data.Money
end
return Manager
i have another system for getting the money and it works perfectly fine. But for some reason the buy system just doesnt work. Any suggestions on how to fix this?