I made a script where when you press R you do a punch animation and release a shockwave, it works fine when playing alone but when multiple players use the script during the few seconds it's active then the shockwave's mesh teleports to the player who used it last even though it's supposed to clone a separate one from serverstorage.
When I tried using Instance.new("Part") instead of cloning in a mesh from serverstorage it worked fine.
The script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Table = {}
ReplicatedStorage.RemoteEvent3.OnServerEvent:Connect(function(player)
local function ShockWave()
wait(0.6)
game:GetService("ServerStorage").ShockWaveMesh:Clone().Parent = game.Workspace
local ShockWave = game.Workspace.ShockWaveMesh
ShockWave.Position = player.Character.RightHand.Position
ShockWave.Orientation = player.Character.HumanoidRootPart.Orientation
ShockWave.Size = Vector3.new(1,1,0.5)
ShockWave.Transparency = 0.5
ShockWave.CanCollide = false
game:GetService("ServerStorage").ShockWaveMesh2:Clone().Parent = game.Workspace
local BodyVelocity = Instance.new("BodyVelocity")
local ShockWave2 = game.Workspace.ShockWaveMesh2
BodyVelocity.Parent = ShockWave2
ShockWave2.Orientation = ShockWave.Orientation
ShockWave2.Position = ShockWave.Position
ShockWave2.Size = Vector3.new(5,5,5)
ShockWave2.Transparency = 0.5
ShockWave2.CanCollide = false
BodyVelocity.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
BodyVelocity.Velocity = ShockWave.CFrame.lookVector * 40
ShockWave2.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid and hit.Parent.Name ~= player.Name then
local found = false
for i = 1,#Table do
if Table[i] == hit.Parent.Name then
found = true
end
end
if found == false then
table.insert(Table,game.Players:GetPlayerFromCharacter(hit.Parent).Name)
humanoid:TakeDamage(30)
found = true
wait(3)
for i = 1,#Table do
if Table[i] == hit.Parent.Name then
table.remove(Table,i)
end
end
end
end
end)
spawn(function()
for i = 1,100 do
wait()
ShockWave.Size = ShockWave.Size + Vector3.new(1,1,0.01)
ShockWave.Transparency = ShockWave.Transparency + 0.005
ShockWave2.Size = ShockWave2.Size + Vector3.new(1,1,1)
ShockWave2.Transparency = ShockWave2.Transparency + 0.005
if ShockWave.Transparency == 1 or i == 100 or ShockWave2.Transparency == 1 then
ShockWave:Destroy()
ShockWave2:Destroy()
end
end
end)
spawn(function()
for i = 1,100 do
wait()
ShockWave2.Orientation = ShockWave2.Orientation + Vector3.new(0,0,3)
ShockWave2.Position = ShockWave2.Position + Vector3.new(0,0.1,0)
end
end)
end
ShockWave()
end)

1 comment
I don't really understand how giving it a variable fixes it since if you activate the script twice they should have the same variable, but this worked so thank you