Sorry if the title is kind of confusing, couldn't post because of generic wording or something, anyways--
I am trying to make a randomly spawn system, where the script will find a part in a given folder of other parts and clone the item I have given it in ReplicatedStorage on top of that part in the folder. The cloning works - I can have it go randomly and it limits one to each part. However, my script in the item stops working.
Here's the script in place of the item I am cloning:
local proximityPrompt = script.Parent
local stick = script.Parent.Parent
game.Players.PlayerAdded:Connect(function(player) -- get localplayer
wait(1) -- allow buffer for leaderstats to load
proximityPrompt.Triggered:Connect(function()
player.leaderstats.Sticks.Value = player.leaderstats.Sticks.Value + 1 -- gives one coin for interaction
stick:Remove() -- destroys part for interaction
end)
end)
This is the script of the duplicator:
local stickSpawns = game.Workspace.StickSpawns
local stick = game.ReplicatedStorage.Stick
local stickSpawnTable = stickSpawns:GetChildren()
local maxSticks = #stickSpawnTable
local sticksSpawned = 0
function countSticks()
sticksSpawned = 0
for i, s in pairs(stickSpawnTable) do
if s:FindFirstChild("Stick") then
sticksSpawned += 1
end
end
return sticksSpawned
end
function StickSpawner()
while true do
local amountOfSticks = countSticks()
if amountOfSticks < maxSticks then
local stickClone = stick:Clone()
local randomSpawn
repeat
randomSpawn = stickSpawnTable[math.random(1, #stickSpawnTable)]
until not randomSpawn:FindFirstChild("Stick")
stickClone.Parent = randomSpawn
stickClone.CFrame = randomSpawn.CFrame + Vector3.new(0,3,0)
end
wait(1)
end
end
wait(1)
spawn(StickSpawner)
Some things I may note, it may be the ProximityPrompt not working inside the script, I've tried adding a print inside of it to debug and got nowhere. Also, the script actually works sometimes, like once in the group of clones then stops. It's random which one does work too.
If you have any other needed info let me know, I cannot figure this out for my life and will do anything to get it fixed.

2 comments
I'd like to ask is the script inside the cloned item a LocalScript or a Script?
It is a plain Script.