Hi! I’ve been working on a fighting game recently, and one of the specific moves requires a specific part to be created in the player’s hand and animate with the player. I’ve followed this tutorial, and the animations work well in the animation editor. The issue is in the actual game the hammer doesn’t animate with the player.
-
What do you want to achieve? Make the Hammer animate in-game with the player
-
What is the issue? In Animation Editor in-game
-
What solutions have you tried so far? I’ve looked through the comments on the page I listed already, and have found nothing that helped in there so far, Ill share my code below (both server and local).
Local Script:
local player = game.Players.LocalPlayer
local db = true
local damaged = false
local Chat = false
local animR = Instance.new("Animation")
animR.AnimationId = "http://www.roblox.com/asset/?id=6510114251"
local char = player.Character
wait()
local userInputService = game:GetService("UserInputService")
userInputService.InputBegan:Connect(function(input,gameProcessedEvent)
if gameProcessedEvent then
Chat = true
else
Chat = false
end
end)
game:GetService("UserInputService").InputBegan:Connect(function(input, event, GameStuff)
if GameStuff then return end
if input.KeyCode == Enum.KeyCode.T and db and Chat == false and game.Players.LocalPlayer.Character:FindFirstChild("JHamon")~= nil then
db = false
local playAnim = script.Parent.Parent:WaitForChild("Humanoid"):LoadAnimation(animR)
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 0
game.Players.LocalPlayer.Character.Humanoid.JumpPower = 0
game.ReplicatedStorage.JHamonReps.AttachHammer:FireServer()
wait(0.1)
char.Torso.ToolGrip.Part0 = char.Torso
char.Torso.ToolGrip.Part1 = char.JhamonHammer.BodyAttach
wait(0.1)
playAnim:Play()
game.ReplicatedStorage.ACD:FireServer()
script.Parent.Parent:WaitForChild("JhamonHammer").JHamonHammer.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and not db and not damaged and hit.Parent.Humanoid ~= game.Players.LocalPlayer.Character.Humanoid then
if game.Players.LocalPlayer.Character.Humanoid.Health > 0 then
damaged = true
game.ReplicatedStorage.JHamonReps.HammerHit:FireServer(hit.Parent.Humanoid)
end
end
end)
wait(1)
game.ReplicatedStorage.JHamonReps.DetachHammer:FireServer()
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 17
game.Players.LocalPlayer.Character.Humanoid.JumpPower = 50
wait(8)
damaged = false
db = true
end
end)
Server Script:
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local M6D = Instance.new("Motor6D", char.Torso)
M6D.Name = "ToolGrip"
end)
end)
sound = game.ReplicatedStorage.Sounds.punch
game.ReplicatedStorage.JHamonReps.JHPunchHit.OnServerEvent:Connect(function(player)
local csound = sound:Clone()
csound.Parent = player.Character.Head
wait(0.1)
csound:Play()
end)
local PTL = 2
game.ReplicatedStorage.ACD.OnServerEvent:Connect(function()
PTL = 2
wait(1)
PTL = 1
wait(1)
PTL = 0
end)
game.ReplicatedStorage.JHamonReps.HammerHit.OnServerEvent:Connect(function(player, humanoid)
print("Server Fired")
if humanoid.Health >= 40 and PTL > 1 then
humanoid.Health = humanoid.Health - 40
elseif humanoid.Health < 40 and PTL > 0 then
humanoid.Health = 0
end
end)
game.ReplicatedStorage.JHamonReps.AttachHammer.OnServerEvent:Connect(function(plr,location, playAnim)
local hammer = game.ReplicatedStorage.JhamonHammer:Clone()
hammer.Parent = plr.Character
plr.Character.Torso.ToolGrip.Part0 = plr.Character.Torso
plr.Character.Torso.ToolGrip.Part1 = hammer.BodyAttach
wait()
end)
game.ReplicatedStorage.JHamonReps.DetachHammer.OnServerEvent:Connect(function(plr)
plr.Character.JhamonHammer:Destroy()
plr.Character.Torso.ToolGrip.Part1 = nil
end)
Forgive me for any mistakes in formatting, this is my first time posting on this site. Thanks for your help!