Ducky sometimes dosent clone

  1. What do you want to achieve?

When a remoteEvent is fired the server clones a random ducky and puts it into workspace
but when you have a lot of duckys the clone dosent appear in roblox

  1. What is the issue?

When there is more ducks that already spawned. When it trys to clone the duck it dosent appear in workspace? Am i doing something wrong here? I want duplicated ducks to appear in the pool

  1. What solutions have you tried so far?

I tried looking everywhere but i cant seem to find a solution for this

local repStorage = game:GetService("ReplicatedStorage")
local events = repStorage:FindFirstChild("Events")
local badgeservice = game:GetService("BadgeService")
local id = 2132521717

local ducks = repStorage:FindFirstChild("Ducks")
local SpecialDucks = repStorage:FindFirstChild("SpecialDucks")
local DucksToSpawn = ducks:GetChildren()

local SpawnDuck = events:FindFirstChild("SpawnDuck")

SpawnDuck.OnServerEvent:Connect(function(player)
	local rng = math.random(1,100)
	print(rng)
	local duck = DucksToSpawn[math.random(1,#DucksToSpawn)]
	duck:Clone()
	duck.Parent = workspace
	if rng == 100 then
		badgeservice:AwardBadge(player.UserId,id)
		local duckyspecial = SpecialDucks.GoldenDucky:Clone()
		duckyspecial.Parent = workspace.Ducks
	end
end)

Any help is apreciated!

This may be happening because of lag, if there are so many ducks. I think that you should add print()s inside of the RemoteEvent.OnServerEvent function so that you can check the progress of the event, and see where the code is malfunctioning.

Edit: I see the problem. You need to set the variable duck to DucksToSpawn[math.random(1, #DucksToSpawn)]:Clone(). Because you are setting that variable to the duck that should be cloned, then cloning it and setting the initial duck’s parent to the workspace. You are not setting the variable to the duck to be cloned’s clone. Which means you are parenting the initial duck to the workspace, not the initial duck’s clone.

1 Like

Jayden nailed it. You need to set the clone to a new variable.

local duck = DucksToSpawn[math.random(1,#DucksToSpawn)]:Clone()
duck.Parent = workspace

Ah thanks guys! I really just forgot about that

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