I’ve create a pad for someone that allows for the user to click the pad and the player gets the item for a certain price.
Without the cash check (check if the player has enough to purchase it) it woks perfectly and subtracts the cash from the player, but with the check, if I have lets say 5000 cash, it goes to the else statement even though the price is 1500 and I have enough cash. I don’t know whats wrong. I’m so confused hered.
--Services.
local ServerStorage = game:GetService("ServerStorage")
--References.
local detector = script.Parent
local PurchaseFolder = ServerStorage.Weapons
local price = script.Parent.Parent.Price
--Handles Client To Server & Vise Versa Interactions.
detector.MouseClick:Connect(function(player)
--Local variables not needed to be accessed from the outside of this interaction.
local backpack = player.Backpack
local item = PurchaseFolder:FindFirstChild("DB")
local DataFolder = player:WaitForChild("DataFolder")
local cash = DataFolder:WaitForChild("Currency")
if cash.Value >= price.Value then
--The process of giving the player the item.
local itemClone = item:Clone()
--Check if the player already has the specified item.
if backpack:FindFirstChild("DB") then
backpack:FindFirstChild("DB"):Destroy()
end
itemClone.Parent = backpack
cash.Value = cash.Value - price
print(cash.Value)
print(backpack:GetDescendants())
else
-- You can add a message or handle the case where the player doesn't have enough cash.
print("Not enough cash to purchase the item.")
end
end)
--Services
local ServerStorage = game:GetService("ServerStorage")
--References
local PurchaseFolder = ServerStorage.Weapons
local detector = script.Parent
local price = detector.Parent.Price
print(price.Value)
--Handles Client To Server & Vise Versa Interactions
detector.MouseClick:Connect(function(player)
--Local variables not needed to be accessed from the outside of this interaction
local backpack = player.Backpack
local DataFolder = player:WaitForChild("DataFolder")
local cash = DataFolder:WaitForChild("Currency")
local item = PurchaseFolder.DB
if cash.Value >= price.Value then
--The process of giving the player the item
local itemClone = item:Clone()
--Check if the player already has the specified item
local currentItem = backpack:FindFirstChild("DB")
if currentItem then
currentItem:Destroy()
end
itemClone.Parent = backpack
cash.Value -= price.Value
print(cash.Value)
print(backpack:GetDescendants())
else
-- You can add a message or handle the case where the player doesn't have enough cash
print("Not enough cash to purchase the item")
end
end)
It prints “Not enough cash to purchase the item” which is what happens if the player has not enough. My friend got it to work though with a solution that makes no sense…
changing detector to script.Parent which is… shouldn’t fix the problem but I have a feeling what your solution was would fix it.