Coin System woes


I need to set this up better but I’m drawing a blank. Each coin type spawns in a different area. I got the spawning of parts to work perfectly so now I need an efficient way to differentiate between the coins.

Simply put either a number value for currency in each coin, and then get that from the script.

1 Like
assert(currencyRS, [["The variable currencyRS is nil"]])
assert(#currencyRS:GetChildren() ~= 0, [[The currencyRS doesn't have a children]])
error([[The possible issue is:
- Try currencyRS:GetChildren() (or GetDescandants() if you want to access all children) instead of currencyRS
- Otherwise, it's another issue
]])

Put this in front of the getCoin function

--The command I want you to put

local function getCoin(spawnPart)
--blah blah blah

What it will do is throw an error, A custom error by me, It will stop a function
I hope it works :slight_smile:

Actually when Marusenai said the thing about the value for the currency I remembered I was going to make a Libs Module for all the relevant data. WIP

Then I’m attempting to use it. Still working out how to set it up properly. WIP

--//[[MAIN SPAWN MODULE]]

--//SERVICES
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")

--//VARIABLES
local zoneLibs = require(ServerScriptService:FindFirstChild("Libs").ZoneLibs)
local currencyFolder = ReplicatedStorage:WaitForChild("CurrencyRS")
local islandsFolder = workspace.Islands:GetChildren()

if zoneLibs then
	print("ZoneLibs exists!")
else
	warn("No ZoneLibs found!")
end

local MAX_COINS = 100

--//FUNCTIONS
local FunMod = {}

local function GetPosition(spawnPart)
	--find a random position inside a circle
	local R = spawnPart.Size.X/2

	local a = math.random() * 2 * math.pi
	local r = R * math.sqrt(math.random())

	local x = r * math.cos(a)
	local z = r * math.sin(a)
	local y = spawnPart.Size.Y / 2
	local position = Vector3.new(x, y, z)

	return position
end

function FunMod.CoinManager(spawnPart)
	
	local coinLocation = GetPosition(spawnPart)

end

function FunMod.GemManager() 
	
end

function FunMod.RandNumGen() -- random number generator to choose coin or gem
	
end

function FunMod.GetSpawnLocation(island) -- what do I need to pass in here?

	-- get spawn location from ZoneLibs Module
	
end

function FunMod.GetPlayer(plr) -- get the correct spawn location
	
	for _, player in ipairs(Players:GetPlayers()) do
		if player then
			print(plr.Name, player.Name)
		else
			warn("player doesn't exist")
			-- get info needed to spawn all the coins in 
			-- the correct places on all available islands
			-- for each player that joins
			-- leaderstats island data for each player
			-- example data:
			-- Islands.Island1.isBought = true
			-- Islands.Island2.isBought = false -- all other islands = false
		end
	end

end

return FunMod

I also added in an attribute to the Spawn Parts “CanSpawn = false” so I can use the players saved data to set whether it can spawn or not since the players will need to unlock the new areas over time.

Am I forgetting anything?