Need Help With Proximity Prompt Shop

After I check if the player has the weapon their trying to buy it still takes 100 coins. I’ve tried adding 100 coins after but it still doesn’t work. (I’m relatively new to scripting so please help.)

Screenshot 2024-09-05 201829

1 Like

You’d have to change the order things are done.

The script starts by looking if the value of the coins is above or equal to 100. If it isn’t, THEN it checks for the weapon.

If you test it out, you’ll see that trying to buy the weapon even if you don’t have it or 100 coins will give you 100 coins for free.

What you want to do is check if the player was this weapon first, and if they don’t, then see if they have the money to buy it.

P-S: You should also check if the player’s character is holding the weapon, otherwise you’d be able to buy a duplicate of the weapon by just holding it out!

2 Likes

Thanks but I did that and it still didn’t work

Debounce it if they already own the weapon and don’t bother with the rest, also you’re comparing two different instances, they’re the same instanceto you but they aren’t a clone is not the same instance than the original

also you’re cloning the weapon when you may not need to

script.Parent.Triggered:Connect(function(player)
if player.Backpack:FindFirstChild(weapon.Name) or player.Character:FindFirstChild(weapon.Name) then
 return 
end

local coins=player.leaderstats.Coins

if coins.Value>=100 then
 coins.Value-= 100
local clone= weapon:Clone()
 clone.Parent=player.Backpack
end
end

idk how to indent on pc

1 Like

I tried doing this as well and it still didnt work.