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.
What do you want to achieve? I’d like to get a working spawn and respawn model
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)
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.
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)
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.