Sword Visual Removal Option

Hey guys, so lately I’ve been making a setting where you can change a sword’s excess visuals to be invisible. Unfortunately, since I can’t code very well, I’ve been unable to do so. I’ve even tried ChatGPT to help, but I still reach the same result. However, I can provide the code and hierarchy I’ve made here for you to work off of.

local button = script.Parent
local debounce = false
local replicatedStorage = game:GetService("ReplicatedStorage")

local FlameSword = replicatedStorage:WaitForChild("FlameSword")
local FlameSwordHandle = FlameSword:WaitForChild("Handle")
local FlameSwordMesh = FlameSwordHandle:FindFirstChild("Meshes/FlameSword_Cube.006")
local FlameSwordFire = FlameSwordMesh and FlameSwordMesh:FindFirstChild("Fire")

local GuardianSword = replicatedStorage:WaitForChild("GuardianSword")
local GuardianSwordHandle = GuardianSword:WaitForChild("Handle")
local GuardianSwordMesh = GuardianSwordHandle:FindFirstChild("Meshes/GuardianSword_Cube.006")
local GuardianSwordAbilityParticles = GuardianSwordMesh and GuardianSwordMesh:FindFirstChild("ParticleEmitter")

print("FlameSwordFire:", FlameSwordFire)
print("GuardianSwordAbilityParticles:", GuardianSwordAbilityParticles)

local function toggleParticles()
	if debounce then return end
	debounce = true

	if FlameSwordFire and GuardianSwordAbilityParticles then
		if FlameSwordFire.Enabled or GuardianSwordAbilityParticles.Enabled then
			FlameSwordFire.Enabled = false
			GuardianSwordAbilityParticles.Enabled = false
		else
			FlameSwordFire.Enabled = true
			GuardianSwordAbilityParticles.Enabled = true
		end
		end

	wait(0.5)  
	debounce = false
end
button.MouseButton1Click:Connect(toggleParticles)

image
image

1 Like

This script seems like it is only affecting the tool you have stored in ReplicatedStorage, not necessarily any other instance of it actually existing in the workspace where it would render.

1 Like

Then how do I fix that? I’ve tried using print and stuff to see but nothing shows up.

You could loop through every player’s backpack to find the tool.

I could do that, but I also want it so that selecting off beforehand would affect the tool before it comes into their hand. Essentially changing the storage of the tool.

Thats why you would adjust the tool in the backpack, equipping the tool moves it from the backpack to the character model.

1 Like

I got rid of the stuff about the Guardian Sword as I scrapped it.
Here’s the code I put in (didn’t work):

local button = script.Parent
local debounce = false
local replicatedStorage = game:GetService("ReplicatedStorage")

local FlameSword = replicatedStorage:WaitForChild("FlameSword")

local function toggleParticles(sword)
	local handle = sword:FindFirstChild("Handle")
	if handle then
		local flameMesh = handle:FindFirstChild("Meshes/FlameSword_Cube.006")

		if flameMesh then
			local fire = flameMesh:FindFirstChild("Fire")
			if fire then
				fire.Enabled = not fire.Enabled
			end
		end
	end
end

local function toggleAllParticles()
	if debounce then return end
	debounce = true

	toggleParticles(FlameSword)

	-- Toggle particles for swords that players are holding or have in their backpacks
	for _, player in ipairs(game.Players:GetPlayers()) do
		-- Check the sword in the player's character
		local character = player.Character
		if character then
			local flameSword = character:FindFirstChild("FlameSword")
			if flameSword then
				toggleParticles(flameSword)
			end
		end

		-- Check the sword in the player's backpack
		local backpack = player:FindFirstChild("Backpack")
		if backpack then
			local flameSword = backpack:FindFirstChild("FlameSword")
			if flameSword then
				toggleParticles(flameSword)
			end
		end
	end

	wait(0.5) 
	debounce = false
end

button.MouseButton1Click:Connect(toggleAllParticles)

1 Like

This is the code I used. Placed in a local script in starter character scripts (client sided only). It also supports multiple tool names.

-- Services
local Players = game:GetService("Players")

-- Variables
local LocalPlayer = Players.LocalPlayer
local Mouse = LocalPlayer:GetMouse()

-- Settings 
local ToolNames = {
	"Test", "Test2"
}

-- Functions 
function ToggleParticles(Tool : Tool)
	print("Ran")
	
	local Handle = Tool:FindFirstChild("Handle")
	
	if Handle ~= nil then 
		
		local Fire = Handle:FindFirstChildWhichIsA("Fire") 
		
		if Fire ~= nil then 
			
			Fire.Enabled = not Fire.Enabled 
			
		end
		
	end
end

function ToggleAllParticles()
	for _, Player in ipairs(Players:GetPlayers()) do 
		
		local Backpack = Player.Backpack 
		local Character = Player.Character
		
		-- Going to loop through the backpack and see if any of the tools match any of the names in our ToolNames table 
		-- I'm going to use task.spawn so these code blocks run at the same time. 
		
		task.spawn(function()
			for _,Tool in pairs(Backpack:GetChildren()) do 
				if table.find(ToolNames, Tool.Name) then 

					ToggleParticles(Tool)

				end
			end

		end)
		
		task.spawn(function()
			for _,Tool in pairs(Character:GetDescendants()) do 
				
				if Tool:IsA("Tool") and table.find(ToolNames, Tool.Name) then 
					
					ToggleParticles(Tool)
					
					
				end
				
			end
		end)

	end
end


Mouse.Button1Down:Connect(ToggleAllParticles)
1 Like

If you want this to apply to all tools, remove the table.find portion and pass any tool you find to the Toggle function.

1 Like

Ok I willt ry your code when I’m available. Thank you.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.