I am making a zombie defense tycoon and I want to subtract the players value by 250 but everytime it does that the credits values just goes to -250 even tough I started out with 1,500.
local serverstorage = game:GetService("ServerStorage")
local conveyer2 = serverstorage:WaitForChild("Conveyers").Conveyer2
local conveyer3 = serverstorage:WaitForChild("Conveyers").Conveyer3
local debounce = false
local PrimaryCFrame = CFrame.new(-166.8,3.2,10.1)
function CloneCollector()
local collector = workspace:FindFirstChild("Collector1")
collector.PrimaryPart = collector:FindFirstChild("BrickCollector")
local clone = collector:Clone()
clone:SetPrimaryPartCFrame(PrimaryCFrame)
clone.Parent = workspace
collector:Destroy()
end
function CloneConveyer()
local conveyer2 = conveyer2:Clone()
conveyer2.Parent = workspace
local conveyer3 = conveyer3:Clone()
conveyer3.Parent = workspace
end
script.Parent.Touched:Connect(function(hit)
if debounce == false then
debounce = true
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if not player then
return
end
if true then
player.leaderstats.Credits.Value = player.leaderstats.Credits.Value - 250
CloneCollector()
CloneConveyer()
script.Parent:Destroy()
wait(1.5)
debounce = false
else
script.Parent.TextButton.NameText.Text = "Not Enough Credits"
script.Parent.TextButton.PriceText.Text = ""
wait(1.5)
script.Parent.TextButton.NameText.Text = "Expand Conveyer"
script.Parent.TextButton.PriceText.Text = "250 Credits"
debounce = false
end
end
end)

3 comments
You aren't checking if they have 250 credits before subtracting them. You're just checking if 'true'.
Exactly what Dinoz said.
I've made an answer in case you didn't understand. Hopefully it's cleared almost all of your confusion about your script.