Roblox Forum banner

Help with a script

204 Views 3 Replies 2 Participants Last post by  asad45
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
1 - 4 of 4 Posts
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
Oh yeah, it should play an animation when i click but its not working.
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()
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!!
1 - 4 of 4 Posts
Top