whenever the player presses Q to punch it damages the player what do i do?
local user = game:GetService("UserInputService") local play = game:GetService("Players") local player = game.Players.LocalPlayer local character = player.Character local target = player:FindFirstChild("Humanoid") local person = character:WaitForChild("Humanoid") local anim = Instance.new("Animation") local pain = true anim.AnimationId = "rbxassetid://2642258675" local key = Enum.KeyCode.Q local function IsQkeydown() return user:IsKeyDown(key) end local function Input(input, gameProcessedEvent) if not IsQkeydown() then else print("hit") local AnimationTrack = person:LoadAnimation (anim) AnimationTrack:Play() if target.Touched:Connect(function(hit) target:TakeDamage(5) end) then end end end user.InputBegan:Connect(Input)
My question is... How on Earth did any of that code even cause damage!?
You're trying to define the Humanoid through the LocalPlayer, this severely bewilders me!
But, in some twisted universe, you managed to get it get the humanoid of the very player, that's why it's hurting the player.
I recommend you remove the "if" from:
if target.Touched:Connect(function(hit)
would be:
target.Touched:Connect(function(hit)
As GoldAngelInDisguise was hinting towards. I recommend creating a hit function like this (and defining Humanoid properly!):
local hmd = character:WaitForChild("Humanoid",5) local db = false -- debounce (prevents the function from being fired a million times hmd.Touched:connect(function(hit) if db == false then db = true if hit.Parent:IsA("Model") then -- Checks if target is a model if hit.Parent:FindFirstChildOfClass("Humanoid") then -- Checks if the hit object has a humanoid target = hit.Parent:FindFirstChildOfClass("Humanoid") target:TakeDamage(5) end end end wait(0.4) db = false end)
Just how your script didn't even stop working confuses me to the deepest parts of my brain. But I'll just proclaim you're using black Roblox magic and give you that script excerpt to help you during your journey.