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:
01 | model = game.Workspace.Cars.RedCar 1 |
02 | backup = model:clone() -- backs up the model so it can respawn |
03 | while true do |
04 | wait( 5 ) -- regenerates the model after 7 seconds |
05 |
06 | model = backup:clone() -- loads the backup of the model |
07 |
08 | model.Parent = game.Workspace |
09 | model:MoveTo(Vector 3. new(- 105.042 , 203.5 , 100.995 )) |
10 | 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
1 | --First off you want to put your model in ReplicatedStorage |
2 | local model = game.ReplicatedStorage.Cars.RedCar 1 --im assuming this is your model so this is what I'll use |
3 | while true do |
4 | 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 |
5 | backup = model:Clone() -- backs up the model so it can respawn |
6 | backup.Parent = game.Workspace |
7 | backup:MoveTo(Vector 3. new(- 105.042 , 203.5 , 100.995 )) |
8 | end |
9 | --i didnt test |
Here's a on touch script that works!
01 | local model = game.ReplicatedStorage.Cars.RedCar 1 |
02 | wait( 1 ) |
03 | function onTouched(hit) |
04 | local check = hit.Parent:FindFirstChild( "Humanoid" ) |
05 | if check ~ = nil then |
06 | local player = game.Players:GetPlayerFromCharacter(hit.Parent) |
07 | script.Parent.CanTouch = false |
08 | script.Parent.Transparency = 1 |
09 | script.Parent.CanCollide = false |
10 | local backup = model:Clone() |
11 | backup.Parent = game.Workspace |
12 | -- you can use this to set the position versus where it was originally backup.Position = Vector3.new(-105.042,203.5,100.995) |
13 | wait( 5 ) |
14 | script.Parent.CanCollide = true |
15 | script.Parent.Transparency = 0 |
16 | script.Parent.CanTouch = true |
17 | end |
18 | end |
19 | end |
20 | 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.