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
01rs = game:GetService("ReplicatedStorage")
02local sus = game.ReplicatedStorage.Susan:Clone()
03rs.q.OnServerEvent:Connect(function(player)
04    local weld = Instance.new("Weld")
05    local Hum = player.Character.HumanoidRootPart
06    sus.Parent = Hum
07    weld.Name = "Susan"
08    weld.Part0 = sus
09    weld.Part1 = Hum
10    weld.C0 = CFrame.new(0,0,0)
11    weld.C0 = weld.C0 * CFrame.fromEulerAnglesXYZ(math.rad(0),math.rad(180),0)
12    weld.Parent = Hum
13 
14end)
15rs.E.OnServerEvent:Connect(function(player)
16   sus:Destroy()
17 
18end)

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:

01rs = game:GetService("ReplicatedStorage")
02local sus -- do not clone here
03rs.q.OnServerEvent:Connect(function(player)
04    --add this line here
05    sus = game.ReplicatedStorage.Susan:Clone()
06    local weld = Instance.new("Weld")
07    local Hum = player.Character.HumanoidRootPart
08    sus.Parent = Hum
09    weld.Name = "Susan"
10    weld.Part0 = sus
11    weld.Part1 = Hum
12    weld.C0 = CFrame.new(0,0,0)
13    weld.C0 = weld.C0 * CFrame.fromEulerAnglesXYZ(math.rad(0),math.rad(180),0)
14    weld.Parent = Hum
15 
View all 22 lines...

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:

01rs = game:GetService("ReplicatedStorage")
02local sus -- do not clone here
03rs.q.OnServerEvent:Connect(function(player)
04    --add another check here
05    if sus then
06        return --avoid making more than one clone
07    end
08    --add this line here
09    sus = game.ReplicatedStorage.Susan:Clone()
10    local weld = Instance.new("Weld")
11    local Hum = player.Character.HumanoidRootPart
12    sus.Parent = Hum
13    weld.Name = "Susan"
14    weld.Part0 = sus
15    weld.Part1 = Hum
View all 26 lines...

Hope this helps!

Ad

Answer this question