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

Why is my attack script not doing damage? The damage script normally works in other situations.

Asked by 5 years ago

I have created a script that clones a part called "Damager" onto a hitbox. Damager should damage everything it touches, however for some reason it is not dealing damage when it is cloned. This is the script in damager:

1function onTouched(hit)
2        local human = hit.Parent:findFirstChild("Humanoid")
3        if (human ~= nil) then
4                human.Health = human.Health - 2 -- Change the amount to change the damage.
5        end
6end
7script.Parent.Touched:connect(onTouched)

It should work. This next script is the script that makes the attack work:

01local player = game.Players.LocalPlayer
02repeat wait() until player.Character.Humanoid
03local humanoid = player.Character.Humanoid
04local mouse = player:GetMouse()
05 
06 
07 
08local anim = Instance.new("Animation")
10 
11mouse.KeyDown:connect(function(key)
12  if key == "e" then
13    if script.Cooldown.Value == false then
14    script.Cooldown.Value = true
15   local playAnim = humanoid:LoadAnimation(anim)
View all 50 lines...

In theory, all of this should work perfectly, but for some reason it is not dealing damage. Does anyone know why? Please help.

0
I think the problem is at line 12, don’t think keyboard input doesn’t work like that. TTHKKB 12 — 5y

2 answers

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

Welp, I actually dont know what is the error on your script, but i got this one that i used in my old game and it still working

01--// Services
02local UserInputService = game:GetService('UserInputService')
03local ReplicatedStorage = game:GetService('ReplicatedStorage')
04local Players = game:GetService('Players')
05 
06--// Debounces
07local Punching = false
08local Damaging = true
09 
10--// Customisation
11local Damage = 20
12local Cooldown = 0.5
13 
14--// Events
15local PunchEvent = ReplicatedStorage:WaitForChild('PunchEvent')
View all 49 lines...

ALSO.... add a RemoteEvent called "PunchEvent" (its really important that u name it PunchEvent cuz if u dont it wont work. Make this correct answer if it is

0
U can customize it as u want to Shadic1270 136 — 5y
Ad
Log in to vote
0
Answered by
Dfzoz 489 Moderation Voter
5 years ago

Is the damager script disabled? You have to turn disabled to false on the clone of the hitbox you make

0
I added lines to make sure Disabled is off, and it still doesn't do damage. Thanks anyways, though. luckylucas9 0 — 5y

Answer this question