So this is the final problem for my sword framework here is some Expected and Unexpected results
Expected:
- Keep that Animation while moving
- Keep it like that even idling
Unexpected Results:
Code
Client:
-- // Services \\ --
local UIS = game:GetService("UserInputService")
-- // Variables \\ --
local Tool = script.Parent.Parent.Parent.Parent
local Events = Tool:WaitForChild("Events")
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local Humanoid = Character.Humanoid
-- // For Shiftlock \\ --
local PlayerScripts = Player.PlayerScripts
local Values = PlayerScripts.Values
local IsHoldingTool = Values.IsHoldingTool
-- // For UI \\ --
local PlayerGui = Player.PlayerGui
local WeaponMouseIcon = PlayerGui.WeaponMouseIcon
-- // Events \\ --
local PLAY_ANIMATION_EVENT = Events.PlayAnimation
local CHANGE_MOUSE_EVENT = Events.ChangeMouse
local SHIFTLOCK_EVENT = Events.Shiftlock
-- // Animation Tracks \\ --
local AnimationsFolder = Tool.Animations
local SWING_ANIMATION = AnimationsFolder.Swing
local HOLD_ANIMATION = AnimationsFolder.Hold
PLAY_ANIMATION_EVENT.OnClientEvent:Connect(function(AnimationName)
if AnimationName == "Hold" then
local HOLD_ANIMATION_TRACK = Humanoid:LoadAnimation(HOLD_ANIMATION)
-- Play it bruh lol
print("working")
HOLD_ANIMATION_TRACK:Play()
elseif AnimationName == "Swing" then
local SWING_ANIMATION_TRACK = Humanoid:LoadAnimation(SWING_ANIMATION)
local HOLD_ANIMATION_TRACK = Humanoid:LoadAnimation(HOLD_ANIMATION)
-- Play it bruh lol
print("working")
HOLD_ANIMATION_TRACK:Stop()
SWING_ANIMATION_TRACK:Play()
elseif AnimationName == "StopHold" then
local HOLD_ANIMATION_TRACK = Humanoid:LoadAnimation(HOLD_ANIMATION)
-- Play it bruh lol
print("working")
HOLD_ANIMATION_TRACK:Stop()
end
end)
CHANGE_MOUSE_EVENT.OnClientEvent:Connect(function(MouseIcon)
if MouseIcon == "WeaponMouseIcon" then
UIS.MouseIconEnabled = false
WeaponMouseIcon.Enabled = true
elseif MouseIcon == "DefaultMouseIcon" then
UIS.MouseIconEnabled = true
WeaponMouseIcon.Enabled = false
end
end)
SHIFTLOCK_EVENT.OnClientEvent:Connect(function(Response)
if Response == "Enable" then
IsHoldingTool.Value = true
elseif Response == "Disable" then
IsHoldingTool.Value = false
end
end)
Server:
-- // Services \\ --
local RunService = game:GetService("RunService")
-- // Variables \\ --
local Tool = script.Parent.Parent.Parent.Parent
local Events = Tool.Events
-- // Events \\ --
local PLAY_ANIMATION_EVENT = Events.PlayAnimation
local CHANGE_MOUSE_EVENT = Events.ChangeMouse
local SHIFTLOCK_EVENT = Events.Shiftlock
-- // Functions \\ --
local function Yield(s)
local t = tick()
while tick()-t < s do RunService.Stepped:wait() end
return tick()-t
end
Tool.Equipped:Connect(function()
-- Make Motor 6D {first we need the player's character}
local Character = script.Parent.Parent.Parent.Parent.Parent
local Player = game.Players:GetPlayerFromCharacter(Character)
local RightHand = Character.RightHand
-- Creation of Motor6D
local Motor6D = Instance.new("Motor6D")
Motor6D.Name = "Motor6D"
Motor6D.Parent = RightHand
Motor6D.Part0 = RightHand
Motor6D.Part1 = Tool.SwordHandle
PLAY_ANIMATION_EVENT:FireClient(Player, "Hold")
CHANGE_MOUSE_EVENT:FireClient(Player, "WeaponMouseIcon")
SHIFTLOCK_EVENT:FireClient(Player, "Enable")
end)
Tool.Unequipped:Connect(function()
-- Remove Motor6D
local Player = script.Parent.Parent.Parent.Parent.Parent.Parent
local Character = Player.Character
local RightHand = Character.RightHand
-- Removal of MOtor6D
local Motor6D = RightHand.Motor6D
Motor6D.Part0 = nil
Motor6D.Part1 = nil
Motor6D:Destroy()
PLAY_ANIMATION_EVENT:FireClient(Player, "StopHold")
CHANGE_MOUSE_EVENT:FireClient(Player, "DefaultMouseIcon")
SHIFTLOCK_EVENT:FireClient(Player, "Disable")
end)
Tool.Activated:Connect(function()
-- Set Debounce to true then after a few milliseconds then to false
local Player = script.Parent.Parent.Parent.Parent.Parent
local Values = Tool.Values
local SwordDebounce = Values.SwingDelay
if SwordDebounce == false then
SwordDebounce = true
PLAY_ANIMATION_EVENT:FireClient(Player, "Swing")
Yield(.5)
SwordDebounce = false
end
end)
I did it it from this tutorial
The Only Solutions I tried was gripping it but doesn’t work but another one is from the coding but it doesn’t work neither I need an good solution for this problem because this is an essential part of my game thanks!