Unequip Script Not Working

The Unequip doesn’t work at all. None of the prints that I set up for the Unequip runs. The Equip works fine.

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

-- Folders
local RSStorage = RS.Storage
local Models = RSStorage.Models
local Weapons = Models.Weapons
local WeaponsWeld = script.Welds.Weapons
local Events = RSStorage.RemoteEvents
local AnimationsFolder = RSStorage.Animations
local WeaponsAnimationsFolder = AnimationsFolder.Weapons

-- Events
local WeaponsEvent = Events.WeaponsEvent

-- Objects 
local welds = {}

-- Animations
local EquipAnims = {}
local UnEquipAnims = {}
local IdleAnims = {}

-- Values
local EquipDebounce= {}

-- Main Scripting
Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local torso = char.Torso
		
		
		char:SetAttribute("Equipped", false)
		
		local Weapon = Weapons.Katana
		Weapons.Parent = char
		
		welds[plr] = WeaponsWeld.Katana.IdleWeaponWeld:Clone()
		welds[plr].Parent = torso
		welds[plr].Part0 = torso
		welds[plr].Part1 = Weapon
	end)
end)

Players.PlayerRemoving:Connect(function(plr)
	if welds[plr] then 
		table.remove(welds, table.find(welds, welds [plr] ))
	end
end)


-- 
WeaponsEvent.OnServerEvent:Connect(function(plr, action)
	local char = plr.Character
	local hum = char.Humanoid
	local torso = char.Torso
	local rightarm = char["Right Arm"]
	
	if action == "Equip/Unequip" and not char:GetAttribute("Equipped") and not EquipDebounce[plr] then -- Equipping
		EquipDebounce[plr] = true
		print("Equipped")
		
		IdleAnims[plr] = hum.Animator:LoadAnimation(WeaponsAnimationsFolder.Katana.Idle)
		EquipAnims[plr] = hum.Animator:LoadAnimation(WeaponsAnimationsFolder.Katana.Equip)
		EquipAnims[plr].Priority = Enum.AnimationPriority.Action
		EquipAnims[plr]:Play()
		
		EquipAnims[plr]:GetMarkerReachedSignal("Weld"):Connect(function(Param)
			print ("Weld made")
		welds[plr].Part0 = rightarm
		welds[plr].C1 = WeaponsWeld.Katana.HoldingWeaponWeld.C1
		end)
		
		EquipAnims[plr]:GetMarkerReachedSignal("Equipped"):Connect(function(Param)
			print ("Idle Anim Played")
			IdleAnims[plr].Priority = Enum.AnimationPriority.Idle
			IdleAnims[plr]:Play()
			char:SetAttribute("Equipped", true)
			EquipDebounce[plr] = false
		end)
		
	
		
	elseif  action == "Equip/Unequip" and char:GetAttribute("Equipped") then -- Unequipping
		char:SetAttribute("Equipped", false)
		EquipDebounce[plr] = true
		print ("Unequipped")
		IdleAnims[plr]:Stop()
		
		
		UnEquipAnims[plr] = hum.Animator:LoadAnimation(WeaponsAnimationsFolder.Katana.Unequip)
		UnEquipAnims[plr]:Play()
		
		
		
		UnEquipAnims[plr]:GetMarkerReachedSignal("Weld"):Connect(function(Param)
			print ("Weld2 Made")
		welds[plr].Part0 = torso
		welds[plr].C1 = WeaponsWeld.Katana.IdleWeaponWeld.C1
		end)

		UnEquipAnims[plr]:GetMarkerReachedSignal("Unequipped"):Connect(function(Param)
			print("Equipped = false")
			char:SetAttribute("Equipped", false)
			EquipDebounce[plr] = false
		end)
	end
end)
2 Likes

I don’t know what it is. It’s not the animation; it’s not the coding. I reviewed it the entire day. I have no idea.

2 Likes

is this a local script or regular script?

2 Likes

It’s a server sided script (word limit, aaaaa)

2 Likes

I think I figured out what the problem is
image
It’s this line of code that doesn’t run for some reason. It’s the one after the weld. It just breaks the entire script if it isn’t running. I wonder why it isn’t when the other event is being run perfectly fine. Yes, I updated the animations, but it still wouldn’t run. I could try adding on a parameter.

1 Like

I looked at another forum. It tells me to make another keyframe after the last. I’ll try it out and get back to you.

Yeah, adding another event at the end didn’t work. The script is fine. It has to be related to the event in the animation.

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