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

How do you make the damaging part of the script work?

Asked by 5 years ago
punch = false
damage = true
plr = game.Players.LocalPlayer
while not plr.Character do
    wait()
end

plr:GetMouse().KeyDown:Connect(function(k)
    ctr = plr.Character
    hum = ctr:WaitForChild("Humanoid")
    LeftArm = ctr:WaitForChild("Left Arm")
    ctr = plr.Character
    PunchAnim = Instance.new("Animation")
    PunchAnim.AnimationId = "https://web.roblox.com/asset/?id=".."2523553984"--put id here
    PunchAnimTrack = hum:LoadAnimation(PunchAnim)
    Power = game.Players.LocalPlayer.PlayerGui.MenuGui.StatsFolder.StrengthValue.Value
    Strength = game.Players.LocalPlayer.PlayerGui.MenuGui.StatsFolder.Strength
    if k == "e" then
        if punch == false then
            punch = true
            damage = false
            PunchAnimTrack:Play()
            wait(0.5)
            punch = false
            damage = true
        end
    end
end)
while punch do
    LeftArm.Touched:Connect(function(hit)
        if damage == false then
        damage = true
        human = hit.Parent:WaitForChild("Humanoid")
        human:TakeDamage(Power)
        wait(0.5)
        damage = false
    end
    end)
end

This is the script I used. Yes, I have tried printing and I don't seem to find the issue. No errors in output. The punching animation does work. If you know the answer to this, then tell me as soon as possible.

0
Is this in a localscript? poke7667 142 — 5y
0
yep HappyTimIsHim 652 — 5y
0
its in starterpack HappyTimIsHim 652 — 5y
1
Don't use KeyDown, it is deprecated. Use UserInputService instead. poke7667 142 — 5y
View all comments (2 more)
0
If you want it to damage the player, you can just subtract from the player's health (found in the humanoid) exxtremestuffs 380 — 5y
0
KeyDown is not a valid event of the player's Mouse because mice don't have keys DeceptiveCaster 3761 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Replace line 8 with:

plr:GetMouse().Button1Down:Connect(function(k)

The reason why I'm saying this is because the Player's Mouse object does not have an event named KeyDown. KeyDown is a deprecated event and should not be used. Methods similar to KeyDown (i.e. IsKeyDown()) are meant for keyboards and not computer mice.

A similar solution involves using the UserInputService to get the mouse input. The UserInputService is actually BETTER than the Mouse class with the reason being that the Mouse class is about to be deprecated. If using the UserInputService, use the method IsMouseButtonDown(). That'll help you out quite a bit.

0
gonna user userinputservice now on and thx HappyTimIsHim 652 — 5y
0
i only accepted your answer because of userinputservice and Button1Down doesn't work. If you read my description it said the damaging part of the script HappyTimIsHim 652 — 5y
Ad

Answer this question