Sorry if the code you see is bad to you.
So in my module I made welds for my weapons and changing it when equip. It works for the equip part, but when unequip it’s stuck on the hand, and not returning to its resting position(welded to torso). So I put prints and found the problem, it changes the value lots of times from what I see in my output, and I don’t know how to fix it. It’s either the client script or module script causing the error.
--- client
local RS = game:GetService("ReplicatedStorage")
local tool = script.Parent
local plr = game.Players.LocalPlayer
local char = plr.Character
local Animator = char.Humanoid.Animator
local weapon = char:WaitForChild("Weapon")
local Events = RS.Events
local equipEvent = Events:WaitForChild("equipEvent")
local attackAnims = weapon.attackAnims
local equipAnims = weapon.equipAnims
local equipAnim = Animator:LoadAnimation(equipAnims.equip)
local unequipAnim = Animator:LoadAnimation(equipAnims.unequip)
tool.Equipped:Connect(function()
equipAnim:GetMarkerReachedSignal("weld"):Connect(function()
equipEvent:FireServer()
end)
equipAnim:Play()
end)
tool.Unequipped:Connect(function()
unequipAnim:GetMarkerReachedSignal("weld"):Connect(function()
equipEvent:FireServer()
end)
unequipAnim:Play()
end)
--- Module Script
local Weld = {}
local RS = game:GetService("ReplicatedStorage")
local Models = game.ReplicatedStorage.Models
local weaponModels = Models.Weapons
local weaponWelds = script.welds
local Events = RS.Events
local equipEvent = Events:WaitForChild("equipEvent")
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local charValues = char:WaitForChild("valuesFolder")
local torso = char.Torso
local weaponModel = weaponModels[charValues.Weapon.Value]:Clone()
weaponModel.Parent = char
weaponModel.Name = "Weapon"
local weldValues = weaponWelds[charValues.Weapon.Value]
local weld = Instance.new("Motor6D")
weld.Parent = char
weld.Name = "weaponWeld"
weld.Part0 = torso
weld.Part1 = weaponModel
weld.C1 = weldValues.weaponRest.C1
end)
end)
function Weld.weldEquip(char)
local charValues = char:WaitForChild("valuesFolder")
local weld = char:WaitForChild("weaponWeld")
local tool = char:FindFirstChildOfClass("Tool")
local torso = char.Torso
local rightArm = char["Right Arm"]
if tool and tool.Name == charValues.Weapon.Value then
print(charValues.Equipped.Value)
local weldValues = weaponWelds[charValues.Weapon.Value]
if not charValues.Equipped.Value then
charValues.Equipped.Value = true
else
charValues.Equipped.Value = false
end
end
end
equipEvent.OnServerEvent:Connect(function(plr)
Weld.weldEquip(plr.Character)
end)
return Weld
I also appreciate for suggestions for improving.