#Incorrect value

1 messages · Page 1 of 1 (latest)

spark magnet
#

i can't figure out why this is happening but whenever i purchase 'Double Tap' it seems to take away triple the amount it should. the price is 2500, it takes away 7500

local dt = game.Workspace.BZInteractables["Double Tap"].Origin
local prompt = dt:WaitForChild("ProximityPrompt")
local cost = game.Workspace.BZInteractables["Double Tap"].Cost.Value
local purchased = false

local function perkPurchase(item)
if purchased == false then
game.SoundService.SFX.Purchase:Play()
purchased = true
else
return
end
end

local function pointDecrease(Player)
if purchased == false then
local leaderstats = Player:WaitForChild("leaderstats")
local Points = leaderstats:WaitForChild("Points")
Points.Value -= cost
else
return
end
end

prompt.Triggered:Connect(function(player) -- Triggered passes the player who activated it
pointDecrease(player)
perkPurchase(dt)
end)

#

Note: 'Cost' is a numbervalue, its value is 2500

#

here is another item purchase with the same code that works just as intended

meager cargo
#

i think most reason why is when you make a purchased debounce, it globally so when a player1 for example press it, the whole server will toggle it instead your client only

#

so basically all you want to do is when a player triggers, the player will get something and thier money will lost as same as the price?

meager cargo
#

here i make a better version but instead using cost value as int value (from your script) i will set it to attributes so it can easy to change and optimize

local BZInteractables = workspace.BZInteractables

local dt = BZInteractables:WaitForChild("DoubleTap")
local Origin = BZInteractables["DoubleTap"].Origin
local prompt = dt:WaitForChild("ProximityPrompt")
local cost : BasePart = dt:GettAttributes("Cost")

local isPurchased = {}

local function perkPurchase(player : Player, item)
    local leaderstats = player:FindFirstChild("leaderstats")
    local Points = leaderstats:FindFirstChild("Points")
    if not (leaderstats and Points) then return end
    
    if not isPurchased[player.Name] and Points.Value >= cost then
            Points.Value -= cost
            
            game.SoundService.SFX.Purchase:Play()
            isPurchased[player.Name] = true
    else
        print(player.Name.." already bought "..item)
    end
end

prompt.Triggered:Connect(function(player) -- Triggered passes the player who activated it
    perkPurchase(player, dt)
end)
#

also what i change is i made a part's name no more spaces so you can easily use functions

#

you can set the an attribute by scrolling to bottom from your part properties and create a attribute named "Cost" and set the value type to number and set it to 2500

green haven
#

you probably have more than one connection to the same prompt

meager cargo
#

wdym?

spark magnet
spark magnet
#

i'm such an idiot, sorry for making you go through that, i had some copy pasted perks that i haden't yet changed their scripts. they all ran the same function

crystal zincBOT
#

studio** You are now Level 1! **studio

green haven
green haven
meager cargo