VFX Module Script Replicating to all players instead of my player

I’m still a bit new to module scripts and how they work globably and locally. I’m working on a vfx function and I put all of my functions inside of a module script to keep things organized. The problem is the vfx functions and welds from the module script are being replicated to the other players who didn’t even use the moves. It even welds to other player’s HumanoidRootpart, making us stick together. How can I change my module script functions to only work on the player who used the move instead of all players?

Video of me explaining: Module script problem - YouTube

MODULE SCRIPT:

local HakiType = {}

function HakiType.ConquersHakiRed(Player, Character)
	local TweenService = game:GetService("TweenService")
	local Head = Character["Head"]
	local HumanoidRootPart = Character['HumanoidRootPart']
	local ConquerEffects = game:GetService("ReplicatedStorage").VFX.ConquersHaki
	local CircleRing = ConquerEffects.Circle:Clone()
	local Wave3 = ConquerEffects.Wave3:Clone()
	local WindVFX = ConquerEffects["Wind[C.Haki]"]:Clone()
	local Wind2VFX = ConquerEffects["Wind2[C.Haki]"]:Clone()
	local LidVFX = ConquerEffects.FireBall:Clone()
	local Lid = ConquerEffects.Part:Clone()
	
	CircleRing.Parent = HumanoidRootPart
	Wave3.Parent = HumanoidRootPart
	WindVFX.Parent = HumanoidRootPart
	Wind2VFX.Parent = HumanoidRootPart
	Lid.Parent = HumanoidRootPart
	LidVFX.Parent = HumanoidRootPart
	
	
	
	print("Other parts welded")
	local W1 = Instance.new('WeldConstraint')
	W1.Part0 = HumanoidRootPart
	W1.Part1 = Lid
	W1.Name = "Lid [Conquers Haki Red]"
	W1.Part1:PivotTo(HumanoidRootPart.CFrame)
	W1.Parent = HumanoidRootPart
	
	
	local W2 = Instance.new('WeldConstraint')
	W2.Part0 = Lid
	W2.Part1 = LidVFX
	W2.Name = "LidVFX [Conquers Haki Red]"
	W2.Part1:PivotTo(Lid.CFrame)
	W2.Parent = Lid
	
	
	local W = Instance.new('WeldConstraint')
	W.Part0 = HumanoidRootPart
	W.Part1 = CircleRing
	W.Name = "CircleRing [Conquers Haki Red]"
	W.Part1:PivotTo(HumanoidRootPart.CFrame)
	W.Parent = HumanoidRootPart
	
	local T = Instance.new('WeldConstraint')
	T.Part0 = HumanoidRootPart
	T.Part1 = Wave3
	T.Name = "Wave3 [Conquers Haki Red]"
	T.Part1:PivotTo(HumanoidRootPart.CFrame)
	T.Parent = HumanoidRootPart
	
	
	
	local E = Instance.new('WeldConstraint')
	E.Part0 = HumanoidRootPart
	E.Part1 = WindVFX
	E.Name = "WindVFX [Conquers Haki Red]"
	E.Part1:PivotTo(HumanoidRootPart.CFrame)
	E.Parent = HumanoidRootPart
	
	local M = Instance.new('WeldConstraint')
	M.Part0 = HumanoidRootPart
	M.Part1 = Wind2VFX
	M.Name = "Wind2VFX [Conquers Haki Red]"
	M.Part1:PivotTo(HumanoidRootPart.CFrame * CFrame.new(0,15,0))
	M.Parent = HumanoidRootPart
	
	
	
	--Tweening
	
	local info = TweenInfo.new(
		2,
		Enum.EasingStyle.Sine,
		Enum.EasingDirection.Out,
		0,
		false,
		0
	)
	
	local info2 = TweenInfo.new(
		3,
		Enum.EasingStyle.Sine,
		Enum.EasingDirection.Out,
		0,
		false,
		0
	)
	
	local endinfo  = TweenInfo.new(
		
		3,
		Enum.EasingStyle.Quad,
		Enum.EasingDirection.Out,
		0,
		false,
		0
	)
	
	local InfoType = TweenInfo.new( 2,
		Enum.EasingStyle.Sine,
		Enum.EasingDirection.InOut,
		0,
		false,
		0
	)
	local Goal = {Transparency = 0;
		Orientation = Vector3.new(CircleRing.Position) + Vector3.new(0, 3000, 0 );
		Size = Vector3.new(215.596, 1, 226.428)
		
	}
	
	local Goal2 = {Transparency = 0;
		Orientation = Vector3.new(Wave3.Position) + Vector3.new(0,-3000, 0);
		Size = Vector3.new(205.322, 0.584, 234.662)
	}
	
	local endGOAL = { Transparency = 1;
		
	}
	
	
	local Goal3Lid = {Transparency = 0.8;
		Orientation = Vector3.new(Lid.Position) + Vector3.new(0, -2000, 0);
		Size = Vector3.new(197.563, 197.23, 208.115)
	}
	
	local Goal4LidVFX = {Transparency = 0.8;
		Orientation = Vector3.new(Lid.Position) + Vector3.new(0,2000, 0);
		Size = Vector3.new(176.716, 176.418, 186.155);
		Color = Color3.new(1, 1, 1)}
	
	local Created = TweenService:Create(CircleRing, info, Goal)
	local Created2 = TweenService:Create(Wave3, info2, Goal2)
	local LastTween = TweenService:Create(Wave3, endinfo, endGOAL)
	local LastTween2 = TweenService:Create(CircleRing, endinfo, endGOAL)
	local LastTween3 = TweenService:Create(Lid, InfoType, Goal3Lid)
	local LastTween4 = TweenService:Create(LidVFX, InfoType, Goal4LidVFX)
	local LastTween5 = TweenService:Create(Lid, endinfo,endGOAL)
	local LastTween6 = TweenService:Create(LidVFX, endinfo,endGOAL)
	LastTween3:Play()
	LastTween4:Play()
	Created:Play()
	Created2:Play()
	task.wait(1)
	LastTween:Play()
	LastTween2:Play()
	LastTween5:Play()
	LastTween6:Play()
	
	task.wait(3)
	
	--[[Character:FindFirstChild("Circle"):Destroy()
	Character:FindFirstChild("Wave3"):Destroy()
	Character:FindFirstChild("Wind[C.Haki]"):Destroy()
	Character:FindFirstChild("Wind2[C.Haki]"):Destroy()
	Character:FindFirstChild("Part"):Destroy()
	Character:FindFirstChild("FireBall"):Destroy()]]
	
	
	print("All items have been destroyed.")
end

return HakiType

SERVER SCRIPT:

		
	
		
		local ConquerRemote = game:GetService("ReplicatedStorage"):WaitForChild("ConquerClash")
		local Gui = game:GetService("StarterGui").ConquerGui
		local ConquersHakiModule = require(script.ConquersModule)
		local Sound = game.Workspace.Laugh
		local ConquerEffects = game:GetService("ReplicatedStorage").VFX.ConquersHaki
		local BubbleRangeVFX = ConquerEffects["BubbleRange[C.Haki]"]:Clone()
		local ConquersHaki = ConquerEffects["Conqurers Haki"]:Clone()

		local Track


ConquerRemote.OnServerEvent:Connect(function(player, Ins)
	
	if Ins == "Haki" then
		

	
			local Character = player.Character
			local HumanoidRootPart = Character.HumanoidRootPart
			ConquersHaki.Parent = HumanoidRootPart
			BubbleRangeVFX.Parent = HumanoidRootPart



			local G = Instance.new('WeldConstraint')
			G.Part0 = HumanoidRootPart
			G.Part1 = BubbleRangeVFX
			G.Name = "BubbleRangeVFX [Conquers Haki Red]"
			G.Part1:PivotTo(HumanoidRootPart.CFrame)
			G.Parent = HumanoidRootPart


			local R = Instance.new('WeldConstraint')
			R.Part0 = HumanoidRootPart
			R.Part1 = ConquersHaki
			R.Name = "ConquersHaki [Conquers Haki Red]"
			R.Part1:PivotTo(HumanoidRootPart.CFrame)
			R.Parent = HumanoidRootPart
			Sound:Play()

			ConquersHakiModule.ConquersHakiRed(player, Character)
			local Data = {Outcome = "Passout"}
			ConquerRemote:FireClient(player, Data)
			
			for i, enemy in game.Workspace:GetDescendants() do
				
	
				if enemy:IsA("Model") and enemy:FindFirstChild("Humanoid") and enemy.Name ~= player.Name then --Checks
					local Enemy = enemy
					print(Enemy.Name)
					if (Enemy.HumanoidRootPart.Position - player.Character.HumanoidRootPart.Position).magnitude < 60 then
						local Anim = Instance.new("Animation", Enemy)
						Anim.Name = "PassOut"
						Anim.AnimationId = "rbxassetid://11715519098"
						--	Enemy.PlayerGui.ConquerGui.Enabled = true 
						Track = Enemy.Humanoid.Animator:LoadAnimation(Anim)
						Track:Play()
						Enemy.Humanoid.WalkSpeed = 0
						Enemy.Humanoid.JumpHeight = 0 
						
						

						Track:GetMarkerReachedSignal("Freeze"):Connect(function(paramString)
							Track:Stop()
							Enemy:FindFirstChild("PassOut"):Destroy()

							local NewTrack = Instance.new("Animation")
							NewTrack.Name = "Passout"
							NewTrack.AnimationId = "rbxassetid://11717032938"
							NewTrack.Parent = Enemy

							local Track2 = Enemy.Humanoid.Animator:LoadAnimation(NewTrack)
							Track2:Play()
							
							task.wait(10)  
							
							Track2:Stop()
							Anim:Destroy()
							Enemy.Humanoid.WalkSpeed = 16
							Enemy.Humanoid.JumpHeight = 7.2
						end)


					end

				end

		end
		
	end
end)



LOCAL SCRIPT:

player.CharacterAdded:Connect(function(Character)
	local Humanoid = Character:WaitForChild("Humanoid")
	local UIS = game:GetService("UserInputService")
	local ConquerRemote = game:GetService("ReplicatedStorage"):WaitForChild("ConquerClash")
	local GEAR5ANIM = script:WaitForChild("Conqueranim")
	local TweenService = game:GetService("TweenService")
	local Info = TweenInfo.new(
		5,
		Enum.EasingStyle.Sine,
		Enum.EasingDirection.Out,
		1,
		false,
		0
		
	)
	
	local Goal = {BackgroundTransparency = 0.1}
	
	

	UIS.InputBegan:Connect(function(input, GPE)
		if GPE then return end

		if input.KeyCode == Enum.KeyCode.G then


			local Track = Humanoid:LoadAnimation(GEAR5ANIM)
			Track:Play()
			Humanoid.WalkSpeed = 0
			Humanoid.JumpHeight = 0 

			ConquerRemote:FireServer("Haki")
			task.wait(5)
			Track:Stop()
			Humanoid.WalkSpeed = 16
			Humanoid.JumpHeight = 7.2
		end
		
		ConquerRemote.OnClientEvent:Connect(function(Data)
			local ConquerGui = game:GetService("StarterGui"):WaitForChild("ConquerGui")
			local RedFrame = ConquerGui:WaitForChild("RedFrame")
			local BlackFrame = ConquerGui:WaitForChild("BlackFrame")
			local TweenValue = TweenService:Create(BlackFrame, Info, Goal)
			if Data.Outcome == "Passout" then
				ConquerGui.Enabled = true
				TweenValue:Play()
				
				
			end
		end)

	end)
end)

Maybe it’s because you didn’t provide the module’s function the character model?

I just did that just now and it still have the same outcome

You can look at the new vesion, I just changed it

Can you check which weld that connects both characters? I mean its name…

ok i’ll check right now and see.

Can I see more of these, I am trying to see if I’ve got something correct here.

Okay I’ll make another video to explain

Okay so it looks like its the conquer’s haki red that is being welded to the other player’s humanoid root part. But it’s strange because everything else is being welded to the humanoidrootpart as well but it isn’t doing this.

The name of it is called: ConquersHaki [Conquers Haki Red]

Guessing this is the issue?!
Is it being used for every player character?

here goes another video explaining whats going on.
Video: Video Explained - YouTube

Wait howso? And how could I change that?

Idk if it would fix your issue, but maybe you can try to clone one for every player that fires the event and then destroy it after it is not needed.

There’s a lot of code here and it’s hard to piece together the relevant parts. When you say “replicate” I don’t know if you mean the technical term, as in “other clients enacting the same code as a source client,” or if you mean it in another way.

At first glance, I see there’s one ConquerEffects, BubbleRangeVFX, and ConquersHaki being shared between ConquerRemote.OnServerEvent function instances, rather than new versions of each of those effects being created per function instance.

Could you do a more clear “side by side” of what you want to happen vs. what is happening?

1 Like

Okay, Should I explain here or just do another quick video?

Here is another video: video 11 - YouTube

To be clear…
I don’t see any issue regarding your module script neither on the client side one.

What I’m suspecting is the Server Script code before the for loop.
The lines 6, 7 (The Effects) are being used for every player that fires the event while you should instead clone a separate effect for every player like what you’ve already did in your module script’s “ConquersHakiRed” function.

Try this in the server script and remove lines 6, 7:

ConquerRemote.OnServerEvent:Connect(function(player, Ins)
	
	if Ins == "Haki" then
		
			local BubbleRangeVFX = ConquerEffects["BubbleRange[C.Haki]"]:Clone()
			local ConquersHaki = ConquerEffects["Conqurers Haki"]:Clone()	
			

One thing I notice in the LocalScript is that you’re connecting UIS.InputBegan and ConquerRemote.OnClientEvent within a player.CharacterAdded event. This will cause duplicate connections, where there’s multiple instances of the InputBegan and OnClientEvent connections, because the old ones do not get cleared out when you respawn. I’m not sure how relevant this is to the issue at hand, but it is no doubt going to cause problems on its own.

Two types of fixes come to mind for this:

  • StarterCharacterScripts

    1. Remove the player.CharacterAdded listener and unwrap its function contents so that the wrapped code is not inside a listener at all
    2. Move the LocalScript to StarterCharacterScripts
  • Connections Array

    1. While keeping the player.CharacterAdded listener, make an array connectionsArray at the top of the script
    2. When establishing connections, use this syntax: table.insert(connectionsArray, UIS.InputBegan:Connect(etc)) where etc is the function.
    3. At the beginning of the player.CharacterAdded function, clear any potential existing connections with this code:
while #connectionsArray > 0 do
    local removedConnection = table.remove(connectionsArray)
    removedConnection:Disconnect()
end

As for the welding issue, I think this relates to my previous post here:

You’re welding the same effect instance across multiple players’ HumanoidRootParts.

Your method did work, I’m gonna see if theres a better way to optimize this though.

Interesting, I’m going to look into it right now.