Hi, So im making a spawning system for my game using a module script
But for some reason when the player has more cash then the cash required to buy that unit, The player cash is substracted and the playerlimit goes up by 1. But it still return allowspawn as False and wont allow the code to spawn units.
function Unit.Check(player,unit)
local exists = RS.Units:FindFirstChild(unit,true)
local units = exists:FindFirstChild("Stats")
local UnitStats = require(units)
local wave = workspace.Game:WaitForChild("Wave")
local PlayerTowerLimit = player.TowerLimit
local count = 0
local AllowSpawn = false
if exists then
print("found units:", exists)
local cash = game.Players:WaitForChild(player.Name).Cash
if cash.Value >= UnitStats.Cost and wave.Value >= UnitStats.WaveUnlock and PlayerTowerLimit.Value < 30 and count < UnitStats.Limit then
if UnitStats.BeatenBoss then
if badge:UserHasBadgeAsync(player.UserId,127167944370976) then
AllowSpawn = true
cash.Value -= UnitStats.Cost
PlayerTowerLimit.Value += 1
end
elseif UnitStats.DealBadge then
if badge:UserHasBadgeAsync(player.UserId,1760554327123612) then
AllowSpawn = true
cash.Value -= UnitStats.Cost
PlayerTowerLimit.Value += 1
end
else
AllowSpawn = true
cash.Value -= UnitStats.Cost
PlayerTowerLimit.Value += 1
end
end
end
print(AllowSpawn)
return AllowSpawn
end
function Unit.SpawnUnit(player,NewUnit)
local allowed = Unit.Check(player,NewUnit)
print(allowed,NewUnit)
if allowed then
-- code continues