Hello, I am working on a game and this script doesn’t seem to do what I want it to, it works like this, when you click it, it removes 2 “DNA” and unlocks a new buyable item, but it just sets the amount of “DNA” to 0.
local unclear = workspace.InfectBar
local clear = workspace.InfectBarUnclear
local obj = script.Parent.LightUp.Value
local obj2 = script.Parent.LightUp2.Value
local obj3 = script.Parent.LightUp3.Value
local cost = script.Parent.DNACost.Value
local cost2 = (script.Parent.DNACost.Value -1)
script.Parent.ClickDetector.MouseHoverEnter:Connect(function()
clear.Transparency = 0.75
end)
script.Parent.ClickDetector.MouseHoverLeave:Connect(function()
clear.Transparency = 1
end)
script.Parent.ClickDetector.MouseClick:Connect(function(plr)
if plr.leaderstats.DNA.Value >= cost2 then
plr.leaderstats.DNA.Value -= cost
unclear.Size += Vector3.new(1.1,0,0)
unclear.Position += Vector3.new(-0.55,0,0)
clear.Transparency = 1
script.Parent.Decal.Color3 = Color3.new(1,0,0)
obj.Decal.Color3 = Color3.new(1,1,1)
obj.Handler.Disabled = false
obj.ClickDetector.MaxActivationDistance = 99999999999
obj2.Decal.Color3 = Color3.new(1,1,1)
obj2.Handler.Disabled = false
obj2.ClickDetector.MaxActivationDistance = 99999999999
obj3.Decal.Color3 = Color3.new(1,1,1)
obj3.Handler.Disabled = false
obj3.ClickDetector.MaxActivationDistance = 99999999999
script.Parent.ClickDetector:Destroy()
script.Disabled = true
end
end)
Video for further explanation:
(It is only supposed to get deplete only two DNA but instead depletes all DNA)
I’m confused why don’t you just use the cost variable instead of cost2 and check if its greater or equal to the cost, then take away the player’s dna by cost
In my testing, the if statement triggers if the dna value is 1 even though the required cost is 2
local cost = 2
local cost2 = cost-1
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new('Folder', player)
leaderstats.Name = 'leaderstats'
local DNA = Instance.new('IntValue', leaderstats)
DNA.Name = 'DNA'
DNA.Value = 1 -- check if the if statement works
--//
if DNA.Value >= cost2 then
DNA.Value -= cost -- -1
end
if DNA.Value >= cost then
DNA.Value -= cost -- not triggered (as intended)
end
end)