Roblox Forum banner

Help with a script

605 views 3 replies 2 participants last post by  asad45  
#1 ·
Hello, i got a script on my roblox studio that is not working, could someone tell me whats wrong with it?


local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local sword = nil

for i,v in pairs(character:GetChildren()) do
if v:IsA("Tool") and v.Name == "Sword" then
sword = v
break
end
end

if sword then
game:GetService("UserInputService").InputBegan:Connect(function(input, processed)
if input.UserInputType == Enum.UserInputType.MouseButton1 and input.KeyCode == Enum.KeyCode.RightButton and not processed then
humanoid:UnequipTools()
sword.Parent = character
humanoid:EquipTool(sword)
humanoid:SetStateEnabled(Enum.HumanoidStateType.Attacking, true)
end
end)
end
 
#3 ·
I'm pretty sure humanoid:EquipTool auto parents it to the character, also HumanoidStateType.Attacking isn't real, also to make it play a animation, you need to first create the animation, then load it with animator (or humanoid, but its depreacted so I wouldnt recommend it) and then play that animationTrack. Something like this
Code:
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid : Humanoid = character:WaitForChild("Humanoid")
local animator : Animator = humanoid:WaitForChild("Animator")

local AnimationTrack = animator:LoadAnimation(animObjectHere)

AnimationTrack:Play()
 
#4 ·
I'm pretty sure humanoid:EquipTool auto parents it to the character, also HumanoidStateType.Attacking isn't real, also to make it play a animation, you need to first create the animation, then load it with animator (or humanoid, but its depreacted so I wouldnt recommend it) and then play that animationTrack. Something like this
Code:
local player = game.Players.LocalPlayer local character = player.Character or player.CharacterAdded:Wait() local humanoid : Humanoid = character:WaitForChild("Humanoid") local animator : Animator = humanoid:WaitForChild("Animator") local AnimationTrack = animator:LoadAnimation(animObjectHere) AnimationTrack:Play()
Thank you so much for helping!!