Hi evil developpers, i was making a coin spawner system and encountered an annoying problem. I have spawners inside a folder, and coins are supposed to spawn in a folder while being prented to their respective spawner. But here's the problem: On joining, the spawners get destroyed after a few seconds, and the coins respawns idk where.
I looked everywhere, and i don't understand whats going on. Please help, i need ts to work to make my full game.
Heres the script:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Workspace = game:GetService("Workspace")
local DataStoreService = game:GetService("DataStoreService")
local coinStore = DataStoreService:GetDataStore("PlayerCoins")
local coinTemplate = ReplicatedStorage:WaitForChild("CoinTemplate")
local spawnerFolder = Workspace:WaitForChild("CoinSpawners")
local coinsFolder = Workspace:FindFirstChild("Coins")
local respawn = 30
--id giver
for i, spawner in ipairs(spawnerFolder:GetChildren()) do
if spawner:IsA("BasePart") then
spawner:SetAttribute("SpawnerID", "Spawner_" .. i)
end
end
local function spawnCoin(spawner)
local spawnerID = spawner:GetAttribute("SpawnerID")
if not spawnerID then return end
for _, child in ipairs(coinsFolder:GetChildren()) do
if child:GetAttribute("SpawnerID") == spawnerID then
return
end
end
local coin = coinTemplate:Clone()
coin.CFrame = spawner.CFrame * CFrame.new(0,1,0)
coin.Anchored = true
coin.CanCollide = false
coin.Parent = coinsFolder