Clone an item in local if the player didnt took it before

When the player load in the game, I have my datastore to know if the player has taken the potion, that send in a localscript the potion that is not taken but I have a problem.

I have a lot of spawnpoints in a folder

RS.Remotes.BoostNotTaken.OnClientEvent:Connect(function(SpawnName)
	for _, spawnpoints in ipairs(SpawnPoints:GetChildren()) do
		print(spawnpoints)
		if spawnpoints.Name == SpawnName then
			if spawnpoints.BoostType.Value == "BasicLuckBoost" then
				print(spawnpoints.BoostType.Value)
				local BoostNotTaken = RS.Collectibles.BasicLuckBoost:Clone()
				BoostNotTaken.Parent = CollFolder
				BoostNotTaken.Spawnpoint.Value = spawnpoints.Name
				print(BoostNotTaken.Parent)
				BoostNotTaken:SetPrimaryPartCFrame(spawnpoints.CFrame)
			elseif spawnpoints.BoostType.Value == "MediumLuckBoost" then
				local BoostNotTaken = RS.Collectibles.MediumLuckBoost:Clone()
				BoostNotTaken.Parent = CollFolder
				BoostNotTaken.Spawnpoint.Value = spawnpoints.Name
				BoostNotTaken:SetPrimaryPartCFrame(spawnpoints.CFrame)
			end
		end
	end
end)

print(spawnpoints) return me only hive1 to 6

I tried to put in pairs in ipairs SpawnPoints:GetChildren()) SpawnPoints:GetDescendants())
if you can help me :slight_smile:

1 Like

Is the issue that it only prints hive1, hive2, hive3, hive4, hive5 and hive6?

Yes that’s the issue i don’t know why

Have you gone ingame, and when it for loops, checked that the parts are all still in the folder? Because there might be other scripts deleting parts from the folder. So first make sure that they’re all still there.


I launched my game but the part are still in the folder

And they’re all also still there after the for loop has been fired?

Yes, but I just put wait(.2) before the for loop and that worked :slight_smile:

actually that print me a lot of times the same things but now that print me more things than only the hive, but that print me more than just on time idk how many time
image

I don’t understand, are there still issues with the code?

I want that print me only one time all the folder spawnpoint but idk why that print me 2136183 times

Where does it print me?

characters

what do you mean by “Where does it print me?”

Send me your new code, after adding the “wait(0.2)”

RS.Remotes.BoostNotTaken.OnClientEvent:Connect(function(SpawnName)
	wait(0.2)
	for _, spawnpoints in ipairs(SpawnPoints:GetChildren()) do
		print(spawnpoints.Name)
		if spawnpoints.Name == SpawnName then
			if spawnpoints.BoostType.Value == "BasicLuckBoost" then
				print(spawnpoints.BoostType.Value)
				local BoostNotTaken = RS.Collectibles.BasicLuckBoost:Clone()
				BoostNotTaken.Parent = CollFolder
				BoostNotTaken.Spawnpoint.Value = spawnpoints.Name
				print(BoostNotTaken.Parent)
				BoostNotTaken:SetPrimaryPartCFrame(spawnpoints.CFrame)
			elseif spawnpoints.BoostType.Value == "MediumLuckBoost" then
				local BoostNotTaken = RS.Collectibles.MediumLuckBoost:Clone()
				BoostNotTaken.Parent = CollFolder
				BoostNotTaken.Spawnpoint.Value = spawnpoints.Name
				BoostNotTaken:SetPrimaryPartCFrame(spawnpoints.CFrame)
			end
		end
	end
end)

Well, how often is the BoostNotTaken remoteevent being fired? It must be fired quite alot for it to spam like that.

for _, v in pairs(LuckBoostTaken:GetChildren()) do
		if v.Value == false then
			RS.Remotes.BoostNotTaken:FireClient(plr, v)	
		else
			print(v.Name.." Has been collected !")
		end
	end

thats the only way to fire the boostnottaken event

Yeah it’s firing once for every child of “LuckBoostTaken”, so if you want a print statement it will spam, just remove the print statement and it won’t spam.

yes but that print the same things more than only one time and some part are not printed