The Destroy part doesn’t work. Basically I want to make a checkpoint indicator that floats on top of the next checkpoint that you need to go to. I currently have 4 Levels and when it reaches Level 4, it is supposed to disappear from the Destroy() function but it just remains. Even if I die, it doesn’t disappear.
Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("Arrow")
local player = game.Players.LocalPlayer
local ServerStorage = game:GetService("ServerStorage")
local star = ServerStorage:WaitForChild("Star")
local cloneStar = star:Clone()
cloneStar.Parent = game.Workspace
local function onSpawnStar(cloneStar)
while true do
wait(.1)
local level = player.leaderstats.Level.Value
if game.Workspace.Checkpoints:FindFirstChild(level + 1) then
local ls = game.Workspace.Checkpoints:FindFirstChild(level + 1)
cloneStar:MoveTo(ls.Position + Vector3.new(0,10,0))
end
wait(1)
if(player.leaderstats.Level.Value == script.Levels.Value)then
cloneStar:Destroy()
end
if(player.Character.Humanoid.Health == 0)then
cloneStar:Destroy()
end
end
end
remoteEvent.OnServerEvent:Connect(onSpawnStar)
This is the script that automatically calculates how many levels I have in the game using an IntValue. The IntValue is inside of the script I posted previously.
This piece of code is in my obby handler script.
local numLevels = script.Parent.Parent.workspace.Checkpoints:GetChildren()
local levels = 0
for i,v in pairs(numLevels) do
if string.find(v.Name,"%d") and v:isA("UnionOperation") then
levels = levels + 1
end
end
if game.ServerScriptService.ArrowScript.Levels.Value ~= levels then
game.ServerScriptService.ArrowScript.Levels.Value = levels
end
Here is a video of the error I was talking about:
https://gyazo.com/65568dfe972b64110666e427fe5a2bc5
As you can see, it won’t disappear.