Something in this module script is wrong but i dont know what it is

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

The issue i found was the code is like doubled. so if the unit cost 200 i would need 400. But if my cash is on 200 it will run the substracting player cash code and increase player unit limit by one. I wonder what’s causing this honestly

Nevermind it was the client, My bad

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.