So currently if you press 't' a kicking animation occurs, but I wan't it to only happen if you have the tool equipped. How would I do that?
local Player = game.Players.LocalPlayer local Character = Player.Character or Player.CharacterAdded:wait() local Humanoid = Character:WaitForChild("Humanoid") local tool = script.Parent local Mouse = Player:GetMouse() local kicking = Instance.new("Animation", Humanoid) kicking.AnimationId = "http://www.roblox.com/item.aspx?id=273619670" local function keyDown(key) key = key:lower() if key == 't' then local animTrack = Humanoid:LoadAnimation(kicking) animTrack:Play() end end function checkHit() local rLeg = Character:WaitForChild("Right Leg") local damage = 15 rLeg.Touched:connect(function(toucher) if toucher.Parent.Humanoid then local hitHuman = toucher.Parent.Humanoid hitHuman.Health = hitHuman.Health - damage elseif toucher.Humanoid then local hitHuman2 = toucher.Humanoid hitHuman2.Health = hitHuman2.Health - damage end end) end Mouse.KeyDown:connect(keyDown, checkHit)
Yes It's inside of a tool, and It's a local script.
Instead of being hassled with connecting the functions at the end of the script, you can connect them on the same line.
tool.Equipped:connect(function() Mouse.KeyDown:connect(function(key) key = key:lower() if key == "t" then local animTrack = Humanoid:LoadAnimation(kicking) animTrack:Play() end end) end)
Now you don't have to connect every event to a function at the end of the script :D
Hope this helps!