Model Would Not Destroy When Condition Is Met

I have this star model that is clones to workshop and it’s sort of an arrow system for my obby checkpoints. The thing is when I reach my last checkpoint, the star is supposed to be destroyed but it isn’t. The code ends up bugging out and I need help with fixing and fine tuning the code.

Local Script Code:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local arrow = ReplicatedStorage:WaitForChild("Arrow")
local changer = ReplicatedStorage:WaitForChild("ColorChanger")
local star = ReplicatedStorage:WaitForChild("Star")
local Players = game:GetService("Players")


arrow.OnClientEvent:Connect(function()
	local player = Players.LocalPlayer
	
		
	if workspace:FindFirstChild("Star") ~= nil then
		workspace:FindFirstChild("Star"):Destroy()
	end
	if workspace:FindFirstChild("Star") == nil then	
		local cloneStar = star:Clone()	
		cloneStar.Parent = game.Workspace
		
						
		if cloneStar == nil then		
			error("Star Was Not Cloned In ["..cloneStar.Parent:GetFullName().."]!! \n stopping script!!")
		end
		
		while true do		
			wait(.1)
			if player:WaitForChild("leaderstats").Level.Value == script.Levels.Value then		
				cloneStar:Destroy()
				print("Destroyed")
			end		
		end		
	end
end)


That’s the String Value at the side together with the coding

level.Changed:Connect(function(newvalue)
		script.Parent.Parent.StarterPlayer.StarterPlayerScripts.LocalArrowScript.Levels.Value = newvalue
		print("String Updated")
	end)

This is the coding for the String Value

	while true do		
			wait(.1)
			if player:WaitForChild("leaderstats").Level.Value == script.Levels.Value then		
				cloneStar:Destroy()
				print("Destroyed")
			end		
		end		
	end
end)

This piece of code is the main issue

2 Likes

Solved!! I figured out what the issue is and figured out a way to fix it using remote events.