Why won't this work?

local db = true
local character = game.Players.LocalPlayer.Character
local humanoid = character:FindFirstChild(“Humanoid”)
local anim = humanoid:LoadAnimation(script:WaitForChild(“Animation”))
local Tool = script.Parent – This Local Script is Inside the Tool
local EquippedTool = false – A Bool Type of Variable

Tool.Equipped:Connect(function() – When Player Equips
EquippedTool = true – Bool Sets to True
end)

Tool.Unequipped:Connect(function() – When Player Unequipped
EquippedTool = false – Bool Sets to False
end)

– // Now We Want to Check When the Player Presses “E”

local UserInputService = game:GetService(“UserInputService”) – We Define UserInputService

UserInputService.InputBegan:Connect(function(Input,Engine) – When An Input Begins
if not Engine then – This Line Checks if the Player is Not Typing in chat / etc
if Input.KeyCode == Enum.KeyCode.E then – Is Player Pressed ‘E’
if EquippedTool == true then – This Checks if the Tool Is Equipped
print(“Player Pressed E While Tool Equipped”)
local dmg
game:GetService(“UserInputService”).InputBegan:Connect(function(pressed)
if pressed.KeyCode == Enum.KeyCode.C and db then
db = false
anim:Play()
dmg = true
wait(1.3)
dmg = false
db = true
end
end)
– What you want to do
end
end
end
end)

4 Likes

It would be cool to say what type of error you get, or what you want to happen

2 Likes

attempted to call nil with findfirstchild

i want to make it so if the player is holding a weapon and press e with it then an animation plays

1 Like

Instead of FindFirstChild, do WaitForChild

1 Like

you dont think ive tried that? it still says nil

1 Like

Then just change on how you get the character.

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
1 Like
  1. Highlight all your code and click image, your code looks all weird, and I dont understand it.

  2. You don’t even tell us what you want to do and your errors happening.

  3. You just put the code and expect us to be magical robots to tell what is going wrong? We arent servants.

  4. Have you EVEN READ this post here on how to post a post? Why are you even a member, honestly.

1 Like

no need to be rude, im new, also i never seen that before

1 Like

the error fixed but now it says called nil with LoadAnimation

1 Like

Make humanoid a waitforchild again.

1 Like

thank you it works now

<2eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee>

1 Like

ignore that last part i was trying to make it longer so it could send

1 Like

There is a reason they pinned it as the very first post :grin::

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.