I am trying to make a script where, if the player doesn’t have sufficient money (bucks), the item would not go into their inventory, instead triggering a remote event.
However, the remote event still fires (As a client), but the item still goes into the inventory.
Any help as to why this is happening?
Script
local list = {
"Bomb";
"Ball";
}
for _, v in next, click do
if v:IsA("ClickDetector") then
v.MouseClick:Connect(function(plr)
if plr then
if plr.Character:FindFirstChild("Humanoid") then
if not table.find(list,v.Name) then
if not plr.Backpack:FindFirstChild(v.Parent.Name) then
local clone = storage.Weapons:FindFirstChild(v.Parent.Name):Clone()
clone.Parent = plr.Backpack
end
if plr.leaderstats.Bucks.Value == v.Parent.Value.Value then
local clone = storage.Weapons:FindFirstChild(v.Parent.Name):Clone()
clone.Parent = plr.Backpack
else
game.ReplicatedStorage.NotEnough:FireClient(plr,plr)
end
end
end
end
end)
end
end
I thought this was needed at first, but instead I changed the script to this:
script
local list = {
"Bomb";
"Ball";
}
for _, v in next, click do
if v:IsA("ClickDetector") then
v.MouseClick:Connect(function(plr)
if plr then
if plr.Character:FindFirstChild("Humanoid") then
if not table.find(list,v.Name) then
if plr.leaderstats.Bucks.Value >= v.Parent.Value.Value then
if not plr.Backpack:FindFirstChild(v.Parent.Name) then
local clone = storage.Weapons:FindFirstChild(v.Parent.Name):Clone()
clone.Parent = plr.Backpack
end
else
game.ReplicatedStorage.NotEnough:FireClient(plr,plr)
end
end
end
end
end)
end
end