Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Help my punch script isnt working and it makes me take damage how do i fix this?

Asked by 6 years ago

whenever the player presses Q to punch it damages the player what do i do?

01local user = game:GetService("UserInputService")
02local play = game:GetService("Players")
03local player = game.Players.LocalPlayer
04local character = player.Character
05local target = player:FindFirstChild("Humanoid")
06local person = character:WaitForChild("Humanoid")
07local anim = Instance.new("Animation")
08local pain = true
09anim.AnimationId = "rbxassetid://2642258675"
10local key = Enum.KeyCode.Q
11local function IsQkeydown()
12    return user:IsKeyDown(key)
13    end
14 
15 
View all 37 lines...
0
line 23: target.Touched is an event, it does not return a bool but returns a signal where you can connect function listeners GoldAngelInDisguise 297 — 6y
0
How do i do that? EzireBlueFlame 14 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

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:

1if target.Touched:Connect(function(hit)

would be:

1target.Touched:Connect(function(hit)

As GoldAngelInDisguise was hinting towards. I recommend creating a hit function like this (and defining Humanoid properly!):

01local hmd = character:WaitForChild("Humanoid",5)
02 
03local db = false -- debounce (prevents the function from being fired a million times
04hmd.Touched:connect(function(hit)
05    if db == false then
06        db = true
07        if hit.Parent:IsA("Model") then -- Checks if target is a model
08            if hit.Parent:FindFirstChildOfClass("Humanoid") then -- Checks if the hit object has a humanoid
09                target = hit.Parent:FindFirstChildOfClass("Humanoid")
10                target:TakeDamage(5)
11            end
12        end
13    end
14    wait(0.4)
15    db = false
16end)

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.

1
connect is deprecated, use Connect User#24403 69 — 6y
0
wait what, I thought it was the other way around Cvieyra2test 176 — 6y
0
I thought "Connect" was the one that got deprecated lol Cvieyra2test 176 — 6y
0
It still isnt working and im still taking damage from it EzireBlueFlame 14 — 6y
Ad

Answer this question