Script help with my destructible model

Hello, i’m working on a desctruction game where you can spawn pre-made models, destroy them then respawn them. I’ve been having an issue where i cannot respawn the model after i destroy it.

  1. What do you want to achieve? I’d like to get a working spawn and respawn model

  2. What is the issue? Something is wrong with my script. I can spawn the model i want but after i destroy it, it doesnt respawn when i click the button robloxapp-20200807-2136398.wmv (2.1 MB) (Video of the model)

  3. What solutions have you tried so far? I tried to use the output but nothing shows up…

Heres my script:

local button = script.Parent:WaitForChild(“Button”)
local detector = script.Parent:WaitForChild(“Detector”)
local target = script.Parent:WaitForChild(“Target”)

local SS = game:GetService(“ServerStorage”)
local cloneables = SS:WaitForChild(“Cloneables”)
local TC_Model = cloneables:WaitForChild(“YellowBall”)

debounce = false

function MakeIt(plr)
local model = TC_Model:Clone()
model.Name = plr.Name…“Ball”
model.Parent = game.Workspace
model:SetPrimaryPartCFrame(target.CFrame)
model.Owner.Value = plr.Name
end

button.ClickDetector.MouseClick:Connect(function(plr)
if not debounce then
debounce = true
print(plr.Name…" wants to spawn a Ball")

	local parts = detector:GetTouchingParts()
	for i,v in pairs(parts) do
		local isBall = v.Parent:FindFirstChild("IsBall")
		if isBall then
			print("Ball detected...removing")
			local Ball = isBall.Parent
			Ball:Destroy()
		end
	end
	
	local Ball = game.Workspace:FindFirstChild(plr.Name.."Ball")
	if Ball then
		print(plr.Name.." already has a Ball, so removing that one")
		Ball:Destroy()
	end
	
	MakeIt(plr)
	wait(2)
	debounce = false
end

end)

I made it into a model so if I need to describe it more I can.

If anyone knows what I did wrong I would be grateful if you helped me out! :slight_smile:

It’d help to see how you have the model set up

local button = script.Parent:WaitForChild("Button")
local detector = script.Parent:WaitForChild("Detector")
local target = script.Parent:WaitForChild("Target")

local SS = game:GetService("ServerStorage")
local cloneables = SS:WaitForChild("Cloneables")
local TC_Model = cloneables:WaitForChild("YellowBall")

debounce = false

function MakeIt(plr)
	local model = TC_Model:Clone()
	model.Name = plr.Name.."Ball"
	model.Parent = game.Workspace
	model:SetPrimaryPartCFrame(target.CFrame)
	model.Owner.Value = plr.Name
end

button.ClickDetector.MouseClick:Connect(function(plr)
	if not debounce then
		debounce = true
		print(plr.Name.." wants to spawn a Ball")
		
		-- Idk why you need this if you are removing the entire ball
		local TouchGetter = detector.Touched:Connect() -- You have to make it listen for touching parts before getting touching
		local parts = detector:GetTouchingParts()
		for i,v in pairs(parts) do
			local isBall = v.Parent:FindFirstChild("IsBall")
			if isBall then
				print("Ball detected...removing")
				local Ball = isBall.Parent
				Ball:Destroy()
			end
		end
		TouchGetter:Disconnect() -- disconnect the function after it's not needed
		
		local Ball = game.Workspace:FindFirstChild(plr.Name.."Ball")
		if Ball then
			print(plr.Name.." already has a Ball, so removing that one")
			Ball:Destroy()
		end
		
		MakeIt(plr)
		wait(2)
		debounce = false
	end
end)

I can send you some screenshots if you’d like.

Yes, please send screenshots it will help me help you

Alrighty! I’ll grab some screenshots!

The top stuff in the circle is in the workspace. Those are the things that spawn the model and holds the script. the bottom stuff in the red is a folder that holds the model.

Can you show me output when you click

Heres what i got after i clicked the button.

PrimaryPart missing or was never set

It’s mostly at the bottom, the others are just a tag i have.

Set a PrimaryPart to the ball. It’s missing

I made a little pad under the circle, how would i go about making it the primary part?

Never mind, i made it have a primary part.

okay now put it back in SS and test it

It didn’t change when i did that

send me the game file and i’ll fix it