Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

So my script stops working after i destroy a part, what do i do?

rs = game:GetService("ReplicatedStorage")
local sus = game.ReplicatedStorage.Susan:Clone()
rs.q.OnServerEvent:Connect(function(player)
	local weld = Instance.new("Weld")
	local Hum = player.Character.HumanoidRootPart
	sus.Parent = Hum
	weld.Name = "Susan"
	weld.Part0 = sus
	weld.Part1 = Hum
	weld.C0 = CFrame.new(0,0,0)
	weld.C0 = weld.C0 * CFrame.fromEulerAnglesXYZ(math.rad(0),math.rad(180),0)
	weld.Parent = Hum
	
end)
rs.E.OnServerEvent:Connect(function(player)
   sus:Destroy()

end)

this is the script after the input ends and the E server is fired and sus gets destroyed, when i press Q again it plays the animation and all but it doesn't clone the part anymore any help is greatly appreciated

1 comment

0

Instead of just destroying the part try to destroy it an then make a script that clones the part after it is destroyed. Sorry I'm not a very good scripter.

1 answer

✓ Accepted answer

You should be making a new clone everytime q is fired:

rs = game:GetService("ReplicatedStorage")
local sus -- do not clone here
rs.q.OnServerEvent:Connect(function(player)
    --add this line here
    sus = game.ReplicatedStorage.Susan:Clone()
    local weld = Instance.new("Weld")
    local Hum = player.Character.HumanoidRootPart
    sus.Parent = Hum
    weld.Name = "Susan"
    weld.Part0 = sus
    weld.Part1 = Hum
    weld.C0 = CFrame.new(0,0,0)
    weld.C0 = weld.C0 * CFrame.fromEulerAnglesXYZ(math.rad(0),math.rad(180),0)
    weld.Parent = Hum

end)
rs.E.OnServerEvent:Connect(function(player)
	if sus then --important
	   sus:Destroy()
	   sus = nil
	end
end)

That however introduces new problem.If q is fired more than once, after firing E only the last clone will be destroyed. To avoid this situation and to make sure you only have one clone at a time, you can modify it like this:

rs = game:GetService("ReplicatedStorage")
local sus -- do not clone here
rs.q.OnServerEvent:Connect(function(player)
    --add another check here
    if sus then 
        return --avoid making more than one clone
    end
    --add this line here
    sus = game.ReplicatedStorage.Susan:Clone()
    local weld = Instance.new("Weld")
    local Hum = player.Character.HumanoidRootPart
    sus.Parent = Hum
    weld.Name = "Susan"
    weld.Part0 = sus
    weld.Part1 = Hum
    weld.C0 = CFrame.new(0,0,0)
    weld.C0 = weld.C0 * CFrame.fromEulerAnglesXYZ(math.rad(0),math.rad(180),0)
    weld.Parent = Hum

end)
rs.E.OnServerEvent:Connect(function(player)
	if sus then --important
	   sus:Destroy()
	   sus = nil
	end
end)

Hope this helps!

This discussion is preserved as it was. New answers, comments, and votes are closed.