The script below is for a EXP Orb so when someone collects it,it should be Destroyed and after awhile,It would be Cloned and pop back again but I don't see it.
They said there is something on line 15 but I don't know whats wrong,the Output doesn't tell anything. Can anyone help?
local db = true script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") ~= nil then if db == true then db = false local player = game.Players:GetPlayerFromCharacter(hit.Parent) player.leaderstats.XP.Value = player.leaderstats.XP.Value + 1 wait() script.Parent:Destroy() end end end) while true do if db == false then db = true wait(3) script.Parent:Clone() end end
-- instead of repeating 'script.Parent' use a variable to make your script more efficient local Orb = script.Parent local CanCollect = true local OrbClone = Orb:Clone() -- clone the orb before it gets destroyed Orb.Touched:Connect(function(part) -- 'connect' is deprecated, use 'Connect' local parentModel = part.Parent local player = game.Players:GetPlayerFromCharacter(parentModel) if player and CanCollect then CanCollect = false player.leaderstats.XP.Value = player.leaderstats.XP.Value + 1 script.Parent = game.ServerScriptService -- reparent the script so it doesn't get removed after Orb is destroyed Orb:Destroy() wait(5) -- orb respawn cooldown if OrbClone then OrbClone.Parent = workspace end script:Destroy() end end) -- the while loop is unnecessary, just have the touched function handle the orb respawning --while true do -- -- if db == false then -- db = true -- wait(3) -- script.Parent:Clone() --end --end