I recently fixed a respawn script and it works great, but when the objects fall into the void they stop spawning because they get deleted from workspace, meaning they cannot be respawned. Is there any loophole around this without major performance issues?
Here's the current code that I am using:
model = game.Workspace.Cars.RedCar1 backup = model:clone() -- backs up the model so it can respawn while true do wait(5) -- regenerates the model after 7 seconds model = backup:clone() -- loads the backup of the model model.Parent = game.Workspace model:MoveTo(Vector3.new(-105.042,203.5,100.995)) end
So, to expand on my comment and explain it better. I recommend putting the model in ReplicatedStorage. This is extremely useful, it doesn't cause lag plus its always there when you need to clone it again! There's different ways to go about respawning (aka cloning) the model after this so below I will provide you with what I personally use. Also I highly recommend checking out this link! https://developer.roblox.com/en-us/api-reference/class/ReplicatedStorage
--First off you want to put your model in ReplicatedStorage local model = game.ReplicatedStorage.Cars.RedCar1--im assuming this is your model so this is what I'll use while true do wait(5) -- regenerates the model after 5 seconds theres other BETTER ways to do this! you can always use a button or a ontouch function backup = model:Clone() -- backs up the model so it can respawn backup.Parent = game.Workspace backup:MoveTo(Vector3.new(-105.042,203.5,100.995)) end --i didnt test
Here's a on touch script that works!
local model = game.ReplicatedStorage.Cars.RedCar1 wait(1) function onTouched(hit) local check = hit.Parent:FindFirstChild("Humanoid") if check ~= nil then local player = game.Players:GetPlayerFromCharacter(hit.Parent) script.Parent.CanTouch = false script.Parent.Transparency = 1 script.Parent.CanCollide = false local backup = model:Clone() backup.Parent = game.Workspace -- you can use this to set the position versus where it was originally backup.Position = Vector3.new(-105.042,203.5,100.995) wait(5) script.Parent.CanCollide = true script.Parent.Transparency = 0 script.Parent.CanTouch = true end end end script.Parent.Touched:Connect(onTouched)
I hope this helps you. I'm happy to help. If you have any questions don't hesitate to ask.