I made Part0 as the player’s Torso so it was easier to animate
Thats the issue then. Part0 is always supposed to be the object the weld is located in.
Make Part0 the mesh instead of making a new part called handle.
Also change this
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local M6D = Instance.new("Motor6D", char.Torso)
M6D.Name = "ToolGrip"
end)
game.Players.PlayerAdded:Connect(function(player)
local playertool = player:WaitForChild("Backpack"):WaitForChild("Bat"):WaitForChild("LocalScript") -- Change "Bat" to your tool name.
local Animation = Instance.new("Animation", playertool)
Animation.Name = "Run"
Animation.AnimationId = "rbxassetid://5522791201" end)
end)
TO
game.Players.PlayerAdded:Connect(function(plr)
local playertool = plr:WaitForChild("Backpack"):WaitForChild("Bat"):WaitForChild("LocalScript") -- Change "Bat" to your tool name.
local Animation = Instance.new("Animation", playertool)
Animation.Name = "Run"
Animation.AnimationId = "rbxassetid://5522791201"
plr.CharacterAdded:Connect(function(char)
local M6D = Instance.new("Motor6D", char.Torso)
M6D.Name = "ToolGrip"
end)
end)
Using one .PlayerAdded event is more efficient.
Works perfectly, but as I mentioned earlier, the bat does not disappear on deequipping, and the animation plays on pressing W again even if you dequipped it.
(Dequipped but it still runs the anim)
Local script:
local plr = game.Players.LocalPlayer
local tool = script.Parent -- Make sure the local script is inside of the tool.
local equipped = false
local Animation = script:WaitForChild("Run") -- Place animation inside of script.
local runtrack = plr.Character.Humanoid:LoadAnimation(Animation)
tool.Equipped:Connect(function()
equipped = true
end)
tool.Unequipped:Connect(function()
equipped = false
end)
game:GetService("UserInputService").InputBegan:Connect(function(keyPressed, gameProcessed)
if gameProcessed then return end
if not equipped then return end
if keyPressed.KeyCode == Enum.KeyCode.W then
game.ReplicatedStorage.ConnectM6D:FireServer()
runtrack:Play()
repeat
wait()
until not game:GetService("UserInputService"):IsKeyDown(Enum.KeyCode.W)
runtrack:Stop()
end
end)
serverscript
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local M6D = Instance.new("Motor6D", char.Torso)
M6D.Name = "ToolGrip"
end)
game.Players.PlayerAdded:Connect(function(player)
local playertool = player:WaitForChild("Backpack"):WaitForChild("Bat"):WaitForChild("LocalScript") -- Change "Bat" to your tool name.
local Animation = Instance.new("Animation", playertool)
Animation.Name = "Run"
Animation.AnimationId = "rbxassetid://5522791201" --Change to Animation Id
end)
end)
game.ReplicatedStorage.ConnectM6D.OnServerEvent:Connect(function(plr,location)
local char = plr.Character
char.Torso.ToolGrip.Part0 = char.Torso
char.Torso.ToolGrip.Part1 = workspace.MeshPart
end)
Can you put print(equipped)
right after
equipped = false
and show the output results?
Did you use
print(equipped)
or
print("Unequipped")
Use print (equipped) if so.
My bad, I’ll change it right now.
Bat doesn’t appear anymore either
You must have edited the code in the mean time. What did you change?
If it doesn’t work try my original solution, making a weld, Part0 is a part named “Handle” that will be invisible and Part1 can be the mesh.
Try it. I’m sure this will work. It may have something to do with that Motor6D you created to the players torso, try deleting that and using my solution.
Would Handle be in the workspace?
No, inside of the tool, thats how the tool actually figures out what its apperance is.
Putting it into the Tool kind of broke it for me… I had a meshpart in the workspace then it vanishes when I click play and gives this error
What? I’m sorry you didn’t have your handle in the tool this whole time?
I never had a Handle. I set RequireHandle to false.
No wonder why it isnt disappearing.
If you want the character to hold something its better to have a handle, than not.
Problem is, the MeshPart just disappears from existence
Server script responsible for Weld:
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local M6D = Instance.new("Weld", char.Torso)
M6D.Name = "ToolGrip"
end)
game.Players.PlayerAdded:Connect(function(player)
local playertool = player:WaitForChild("Backpack"):WaitForChild("Bat"):WaitForChild("LocalScript") -- Change "Bat" to your tool name.
local Animation = Instance.new("Animation", playertool)
Animation.Name = "Run"
Animation.AnimationId = "rbxassetid://5522791201" --Change to Animation Id
end)
end)
game.ReplicatedStorage.ConnectM6D.OnServerEvent:Connect(function(plr)
local char = plr.Character
char.Torso.ToolGrip.Part0 = game.StarterPack.Bat.Handle
char.Torso.ToolGrip.Part1 = workspace.MeshPart
end)
Do you realize if you add a handle it automatically puts it on the character and it moves with the character. So you don’t even need to use Motor6D. Also, what is this meshpart being used for?
Also StarterPack doesnt work for tools once again, you need to use the players backpack.
The MeshPart is supposed to be the bat