So basically my sword equip, and unequips fine but the thing is the sword sometimes doesn’t go back into the sheath or out of the sheath when it should. Sometimes when Its unequipped it’s still in my right hand and vise-versa. Is this a weld Issue or bad scripting?
Local script:
UserInputService.InputBegan:Connect(function(input, IsTyping)
if IsTyping then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 and cooldown == false and MyCharacter:FindFirstChild("Stun") == nil and Blocking == false and equipped == true then
-- Player can't hit while blocking or if the sword is equipped
MyCharacter.Humanoid.WalkSpeed = 2
MyCharacter.Humanoid.JumpHeight = 0
local CurrentTime = tick()
if CurrentTime - lasthit > 1 then
combo = 1
end
lasthit = CurrentTime
cooldown = true
Animation .AnimationId = AnimationFolder[combo] --[[Basically this plays a certain animation from the folder above in order to the index, which is combo]]
local LoadAnimation = MyCharacter.Humanoid:LoadAnimation(Animation):Play()
local data = {char = MyCharacter, comboN = combo, action = "slash"}
CombatRemote:FireServer(data)
slash(MyCharacter, combo)
if combo == 5 then -- when combo hits the last animation it'll reset it so it goes in a loop
task.wait(0.5) --End lag after a complete combo
combo = 1
else
combo = combo + 1
end
task.wait(.25) --Cooldown time after each hit
cooldown = false
MyCharacter.Humanoid.WalkSpeed = 16
MyCharacter.Humanoid.JumpHeight = 7.2
elseif input.UserInputType == Enum.UserInputType.MouseButton2 and cooldown == false and MyCharacter:FindFirstChild("Stun") == nil and equipped == true then
Animation.AnimationId =BlockingFolder[1]
local load = MyCharacter.Humanoid:LoadAnimation(Animation)
--load:Play()
BlockIdleTrack:Play()
Blocking = true
local data = {Character = MyCharacter, action = "block"}
CombatRemote:FireServer(data)
repeat wait( ) until
Blocking == false or equipped == false
--load:Stop()
BlockIdleTrack:Stop()
elseif input.KeyCode == Enum.KeyCode.E and cooldown == false and MyCharacter:FindFirstChild("Stun") == nil and Blocking == false then
if equipped == true then -- if the sword is already equipped, than unequip
equipped = false
else -- otherwise equip the sword
equipped = true
end
local data = {Character = MyCharacter, action = "equip"}
CombatRemote:FireServer(data)
ServerScript:
function setup(Character)
local handle = ReplicatedStorage.CombatFolder.Sword.Fx.Handle:Clone()
local SwordCaseWeldPart= ReplicatedStorage.SwordWeldPart:Clone() -- Cloning the sword Case
SwordCaseWeldPart.Parent = Character.HumanoidRootPart
local weld = Instance.new("Weld", Character)
weld.Part0 = Character.HumanoidRootPart -- Primary Weld is to the humanoidRootPart
weld.Part1 = SwordCaseWeldPart -- Second is The case
SwordCaseWeldPart.Anchored = false
SwordCaseWeldPart.CFrame = Character.HumanoidRootPart.CFrame -- Putting the sword's models' CFrame to the humanoidRootPart
--- Welding the Sword to the Case
handle.Parent = SwordCaseWeldPart.Case -- Make sure the sword's parent is the case and not the humanoidRootPart
local Weld2 = Instance.new("WeldConstraint") --Second Weld Constraint
Weld2.Name = "SideWeld"
Weld2.Part0 = handle -- First weld should be the sword
Weld2.Part1 = SwordCaseWeldPart.Case --Second weld should be the SwordCase
handle:PivotTo(SwordCaseWeldPart.Case.CFrame * CFrame.new(0,-.2, 2.8)) -- Make sure the Sword Is Pivoted or postion to the SwordCase's CFrame. Tweek it if needed.
Weld2.Parent = handle -- The parent of the second weld should be the Sword.Primary Part or Handle
Character.Equipped.Changed:Connect(function()
if Character.Equipped.Value == true then
print("Equipped")
local SideWeld = handle:FindFirstChild("SideWeld")
if SideWeld then
SideWeld:Destroy()
warn("SideWeld Destroyed")
local Motor6d = Instance.new("Motor6D")
Motor6d.Part0 = Character["Right Arm"]
Motor6d.Part1 = handle
Motor6d.Name = "RightArmMotor"
Motor6d.C1 = CFrame.new(0, 1, 0 ) -- Changes the position/Offset of the sword on the Arm
Motor6d.Parent = Character["Right Arm"]
else
print("Unequipped")
local RightArmMotor = Character["Right Arm"]:FindFirstChild("RightArmMotor")
if RightArmMotor then
RightArmMotor:Destroy()
handle:PivotTo(SwordCaseWeldPart.Case.CFrame * CFrame.new(0,-.2, 2.8))
handle.Parent = SwordCaseWeldPart.Case
local Weld = Instance.new("WeldConstraint")
Weld.Name = "SideWeld"
Weld.Part0 = handle
Weld.Part1 = SwordCaseWeldPart.Case
Weld.Parent = handle
end
Bottom Part of Script:
```lua
elseif data.action == "equip" then
if data.Character:FindFirstChild("Equipped") then
if data.Character.Equipped.Value == false then
data.Character.Equipped.Value = true
else -- Otherwise/ If it's the opposite and the sword was already equipped
data.Character.Equipped.Value = false
end
else -- adding a boolvalue if there wasn't in the first place.
local Equipped = Instance.new("BoolValue")
Equipped.Value = true
Equipped.Name = "Equipped"
Equipped.Parent = data.Character
end
elseif data.action == "setup" then
local Equipped = Instance.new("BoolValue")
Equipped.Value = false
Equipped.Name = "Equipped"
Equipped.Parent = data.Character
end
end)