Apples Not spawning

Hello im currently trying to get apples to spawn on the tree, drop and then despawn but as of now nothing is working and its not spawning anything. Another bug ive come across is when it does spawn it wont spawn another apple until that one has been destroyed.

I will provide anyone who is willing to help with more information on this topic.

Can anyone help?

local RS = game:GetService("ReplicatedStorage")
local AppleTree = game.Workspace.AppleTree
local ApplesClone1 = RS.AppleTreeFruits:GetChildren()
local SpecialFruits = RS.AppleTreeFruits:FindFirstChild("SpecialFruits"):GetChildren()
local LuckyNumber = 50
local NewLuckyNumber = math.random(1, 5)
local DropTime = math.random(50, 1000)
local Folder = game.Workspace.AppleTree.Fruits
local DroppedItem = game.Workspace.DroppedItems

while true do
	for i = 1, 43 do
		task.wait(0.5)
		local Clone = ApplesClone1[i]:Clone()
		Clone.Parent = workspace.AppleTree.Fruits
		local function PlayerTouched(Part)
			local Parent = Part.Parent
			if game.Players:GetPlayerFromCharacter(Parent) then
				Clone.Handle.Anchored = false
			end
		end
		Clone.Handle.Touched:Connect(PlayerTouched)
		local Iftrue2 = math.random(1, NewLuckyNumber)
		task.wait(1)
		if Iftrue2 == NewLuckyNumber then
			Clone.Handle.Anchored = false
			Clone.Parent = workspace.DroppedItems
			
			while Clone.Parent ~= workspace or game.Workspace.DroppedItems do
				wait(3)
				print(Clone.Parent)
			end
		end
		
		while Clone.Parent == workspace.DroppedItems or workspace do
			wait(15)
			Clone:Destroy()
			print("Apple has been destroyed")
		end
	end
end

i think they are not spawning because of these lines:

if Iftrue2 == NewLuckyNumber then
	Clone.Handle.Anchored = false
	Clone.Parent = workspace.DroppedItems
			
	while Clone.Parent ~= workspace or game.Workspace.DroppedItems do
		wait(3)
		print(Clone.Parent)
	end
end

so i recommend you using task.spawn on the while loop

1 Like

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