Coin system for a game

So I want to make a coin system for a game, and there are set coin places around the map where they are placed. So I want it to only add a coin when there are no children of the CoinSpot part, but that part doesn’t seem to work, because it just goes past the repeat… There aren’t any errors in the output. It adds coins properly but it ignores the fact that there already is a coin there

local c = game.Workspace.Map.Coins
while true do
	wait(3)
	local coin_clone = game.ReplicatedStorage.Coin:Clone()
	coin_clone.Parent = c.CoinSpot1
	coin_clone.CFrame = c.CoinSpot1.CFrame
	if c.CoinSpot1:GetChildren() ~= 0 then
	
		repeat  wait(0.1)  until c.CoinSpot1:GetChildren() ~= 1
	end
end

you are trying to get the number of children so in this case you need to do this
if #c.CoinSpot1:GetChildren() ~= 0 then

2 Likes

what does the hashtag thing mean/ do?

it will get the number of the children instead of getting the children themselves.

It means how long it is. You would usually do # on a table to see how long it is, but for this instance your using it to see how many children are in the table generated.

1 Like

I see you already got your answer, however I’d like to give a friendly reminder that searching your question on the forum before you ask it in a post will almost always get you the quickest reply. The odds are, if you are working on something that you can find in a few other games, such as a coin/money system, than most issues you may run into have been run into by other people before. A simple search of your question would have turned up this exact same question for a different scenario not even 3 hours ago. Make something run if it doesn't have any children
The solution there gives a similar answer as to the solution here. I don’t say this to be rude, just as a friendly piece of advice. I have had problems that I thought no one else had. But it turned out that after 10 minutes of hard searching, I found the exact problem and the solution.
I wish you good luck on your game :slight_smile:

1 Like

The # is called the length operator, it has the same effect as string.len().