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
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!