Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 4 years ago
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

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. jakelongstyle3 0 — 4y

1 answer

Log in to vote
0
Answered by
sleazel 1287 Moderation Voter
4 years ago

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!

Ad

Answer this question