Sword constantly shifting between hip and right arm

Hello scripters!!
I’ve been working on a code that makes it so when “H” is pressed, a katana will appear.
It does work, but… not as intended.

Before reading:
I am trying to make the katana go from the hip, into the hand. The katana is 2 accessories. One is for the hip, one is for the Right Arm. The hip katana is in ServerStorage, and so is the Right Arm katana.

I grant the katana into the player based on if they have a certain name or not.

Heres an example of what the script does:

If you didn’t see It, It’s basically the katana is going from my hand to my hip to my hand really quickly. I do not want this. I want to be able to toggle the katana.

Heres the local/client script in StarterCharacterScripts:

local PlayerWithKatana = {"name1", "name2"}
local player = game.Players.LocalPlayer

repeat wait() until player.Character.Humanoid

local ShowKatanaEvent = game.ReplicatedStorage:WaitForChild("ShowKatana")
local SheateKatanaEvent = game.ReplicatedStorage:WaitForChild("SheatheKatana")

local humanoid = player.Character.Humanoid
local mouse = player:GetMouse()
local character = player.Character

local Katana = character:WaitForChild("Katana")
local KatanaHip = character:WaitForChild("KatanaHip")

local KatanaHandle = Katana.Handle
local KatanaHipHandle = KatanaHip.Handle

local KatanaParts = {KatanaHandle.Blade , KatanaHandle.part1  , KatanaHandle.part2  , KatanaHandle.part3  , KatanaHandle.part4  , KatanaHandle.part5 }
local KatanaHipParts = {KatanaHipHandle.Blade , KatanaHipHandle.part1  , KatanaHipHandle.part2  , KatanaHipHandle.part3  , KatanaHipHandle.part4  , KatanaHipHandle.part5 }

Cooldown = false
Equipped = false

mouse.KeyDown:connect(function(key)
	if key == "h" then
		if not Cooldown then
			for i,v in pairs(KatanaHipParts) do
				Equipped = true
				Cooldown = true
				if v.Transparency == 1 then
					SheateKatanaEvent:FireServer()
					wait(.1)
					Cooldown = false
				else
					Cooldown = true
					ShowKatanaEvent:FireServer()
					wait(.1)
					Cooldown = false
				   end	
			   end
			end
		end
	end)

Heres a server script in ServerScriptService that unsheathes the katana.

local ShowKatanaEvent = game.ReplicatedStorage:WaitForChild("ShowKatana")
Cooldown = false

ShowKatanaEvent.OnServerEvent:Connect(function(player)
	Cooldown = true
	local Character = player.Character
	local CharacterName = Character.Name
	
	local Katana = Character:WaitForChild("Katana")
	local KatanaHip = Character:WaitForChild("KatanaHip")
	
	local KatanaHandle = Katana.Handle
	local KatanaHipHandle = KatanaHip.Handle
	
	local KatanaParts = {KatanaHandle.Blade , KatanaHandle.part1  , KatanaHandle.part2  , KatanaHandle.part3  , KatanaHandle.part4  , KatanaHandle.part5 }
	local KatanaHipParts = {KatanaHipHandle.Blade , KatanaHipHandle.part1  , KatanaHipHandle.part2  , KatanaHipHandle.part3  , KatanaHipHandle.part4  , KatanaHipHandle.part5 }
	
	for i,v in pairs(KatanaParts) do
		v.Transparency = 0
		v.CanCollide = false
		
		Cooldown = false
	end
	for i,v in pairs(KatanaHipParts) do
		v.Transparency = 1
		v.CanCollide = false
		Cooldown = false
	end
end)

Heres the server script that sheathes the katana.

local SheatheKatanaEvent = game.ReplicatedStorage:WaitForChild("SheatheKatana")
Cooldown = false

SheatheKatanaEvent.OnServerEvent:Connect(function(player)
	Cooldown = true
	local Character = player.Character
	local CharacterName = Character.Name
	
	local Katana = Character:WaitForChild("Katana")
	local KatanaHip = Character:WaitForChild("KatanaHip")
		
	local KatanaHandle = Katana.Handle
	local KatanaHipHandle = KatanaHip.Handle
	
	local KatanaParts = {KatanaHandle.Blade , KatanaHandle.part1  , KatanaHandle.part2  , KatanaHandle.part3  , KatanaHandle.part4  , KatanaHandle.part5 }
	local KatanaHipParts = {KatanaHipHandle.Blade , KatanaHipHandle.part1  , KatanaHipHandle.part2  , KatanaHipHandle.part3  , KatanaHipHandle.part4  , KatanaHipHandle.part5 }
	
	for i,v in pairs(KatanaParts) do
		v.Transparency = 1
		v.CanCollide = false
		Cooldown = false
	end
	for i,v in pairs(KatanaHipParts) do
		v.Transparency = 0
		v.CanCollide = false
		Cooldown = false
	end
end)

Heres the server script in Workspace that grants the katana.

local players = {"name1", "name2"}
local Katana = game.ServerStorage.Katana
local KatanaHip = game.ServerStorage.KatanaHip

game.Players.PlayerAdded:connect(function(plr)
	plr.CharacterAdded:connect(function(chr)
		for i = 1, #players do
			if players[i] == plr.Name then 
				Katana:Clone().Parent = plr.Character
				KatanaHip:Clone().Parent = plr.Character
			end
		end
	end)
end)

Heres the RemoteEvents that power the katana:
RemoteEvents

Any help is appreciated.

I figured it out myself. You dont need to help anymore

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