Regenscript doesn't work when ship crashes into void

When I fly the spaceship downwards and eventually crash into the void, I die. When I go to the Regen button, nothing happens anymore. Usually it works when the ship is still somewhere, but now it does not. Anyone know why?

wait(5) 
local regen = script.Parent
local Racer = script.Parent.Parent.Parent:WaitForChild("Racer")
local purchases = script.Parent.Parent.Parent
local purchasedObjects = script.Parent.Parent.Parent.Parent.PurchasedObjects
local clone = Racer:Clone()
local active = true --debounce
local playerName = script.Parent.Parent.Parent.Parent.Owner.Value.Name
local folderName = playerName.."Ships"
local serverLocation = game.ServerStorage:WaitForChild(folderName)
clone.Parent = serverLocation

regen.Touched:Connect(function(hit)
	if active then
		local active = false
		local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
		if player then
			if script.Parent.Parent.Parent.Parent.Owner.Value == player then
				script.Parent.Parent.Parent.Racer:Destroy()
				local cloclone = clone:Clone()
				cloclone.Parent = purchasedObjects
			end --future shooting, body will have health bar, when 0, body+seat+player destroyed.
			--model remains, when regenerate destroy model, get new. No outside script needed
		end
		wait(3)
		active = true
	end
end)
2 Likes

The problem is the line: script.Parent.Parent.Parent.Racer:Destroy()
Since the ship crashes in the void, it no longer exists, and that line is not passed. It is fixed with a simple if :findfirstchild() then

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.