I need help with this script. I am kinda confused about using functions and loops at the same time, don't know if it will work. Here is the 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)

10 comments
Gonna try it now, can't believe I overlooked that but the while true do loop can work with the function, right?
It worked.
glad i could be of help ^^
Yh man, but for some reason the star doesn't destroy, I keep having that problem. Any reason why??
I'd need more information on what's that "Levels" value inside the script and how does it change in order to try to figure out why it doesn't work as intended.
Okay I will handle that now.
Posted it.
I posted it as an answer, just scroll down ;)
in the first script i would delete that wait(1) and i'd put if(player.leaderstats.Level.Value >= script.Levels.Value) maybe?
That would exhaust the script.