01 | rs = game:GetService( "ReplicatedStorage" ) |
02 | local sus = game.ReplicatedStorage.Susan:Clone() |
03 | rs.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.Part 0 = sus |
09 | weld.Part 1 = Hum |
10 | weld.C 0 = CFrame.new( 0 , 0 , 0 ) |
11 | weld.C 0 = weld.C 0 * CFrame.fromEulerAnglesXYZ(math.rad( 0 ),math.rad( 180 ), 0 ) |
12 | weld.Parent = Hum |
13 |
14 | end ) |
15 | rs.E.OnServerEvent:Connect( function (player) |
16 | sus:Destroy() |
17 |
18 | 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:
01 | rs = game:GetService( "ReplicatedStorage" ) |
02 | local sus -- do not clone here |
03 | rs.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.Part 0 = sus |
11 | weld.Part 1 = Hum |
12 | weld.C 0 = CFrame.new( 0 , 0 , 0 ) |
13 | weld.C 0 = weld.C 0 * CFrame.fromEulerAnglesXYZ(math.rad( 0 ),math.rad( 180 ), 0 ) |
14 | weld.Parent = Hum |
15 |
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:
01 | rs = game:GetService( "ReplicatedStorage" ) |
02 | local sus -- do not clone here |
03 | rs.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.Part 0 = sus |
15 | weld.Part 1 = Hum |
Hope this helps!