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

My sword script is not doing damage to enemies?

Asked by
zomspi 541 Moderation Voter
5 years ago

I got a sword script off of youtube and modified it but it doesn't work?

01if script.Parent.Blade.Touched == game.Workspace.Enemies.Dark4 then
02 
03if script.Parent.CanDamage.Value == true then
04 
05script.Parent.CanDamage.Value = false
06 
07game.Workspace.Enemies.Dark4.Zombie.Health = game.Workspace.Enemies.Dark4.Zombie.Health - 100
08else
09    print("no")
10end
11 
12end
0
for game.Workspace.Enemies.Dark4.Zombie.Health - 100 you did this - instead of this = oziase 1 — 5y
0
that was just a test, I am wanting to take like 20 health off of it zomspi 541 — 5y
0
It's not your sword script, it's a random person's sword script. We don't help with free code. hiimgoodpack 2009 — 5y
0
but it is mine? Line 2 and 3 are theirs the rest is mine zomspi 541 — 5y
0
Line 2 is a blank line and it wouldn't make sense for 3 to be made by you but the rest not because on line 5 it does something which supports the functionality line 3 gives. hiimgoodpack 2009 — 5y

3 answers

Log in to vote
0
Answered by
Gingerely 245 Moderation Voter
5 years ago
Edited 5 years ago

Well, in this case for iv loop is the best, so the script I made here, you will not need to make new scripts, just get an npc and put it in the enemies folder, it will automatically take damage if the sword touches the npc. Btw this script should be in the tool and im assuming you have a part named Blade.

01local enemies = game.Workspace.Enemies:GetChildren() --// All the children of the enemies folder.
02 
03 
04for i, v in pairs(enemies) do
05    if v:IsA("Model") then --// If the child is a model
06        if v:FindFirstChild("Humanoid") then --// If the model has a humanoid
07            wait(1)
08            v.HumanoidRootPart.Touched:Connect(function() --// When the sword touches the npc
09                v.Humanoid:TakeDamage(10) --// Npc takes 10 Damage
10                wait(1)
11            end)
12        end
13    end
14    end

OR you can use this one that only will damage when you click with the tool!

01local enemies = game.Workspace.Enemies:GetChildren() --// All the children of the enemies folder.
02 
03 
04for i, v in pairs(enemies) do
05    if v:IsA("Model") then --// If the child is a model
06        if v:FindFirstChild("Humanoid") then --// If the model has a humanoid
07            wait(1)
08            v.HumanoidRootPart.Touched:Connect(function()--// When the sword touches the npc
09                script.Parent.Activated:Connect(function() --// If you click holding the sword it will damage.
10                v.Humanoid:TakeDamage(10) --// Npc takes 10 Damage
11                wait(1)
12            end)
13            end)
14            end
15    end
16    end
0
When I hit my enemy it doesn't do damage still. I know it isn't the enemy because with the classic sword it works, I would use the classic sword but it uses a mesh and I can't make meshes zomspi 541 — 5y
0
nvm I needed the rename something, thanks! zomspi 541 — 5y
Ad
Log in to vote
1
Answered by 5 years ago

Instead of doing all this extra, you need to target what the sword is hitting instead of referencing the workspace. For example:

01local sword = script.Parent
02local dmg = #ofdamageuwantswordtodo
03 
04sword.Touched:Connect(function(hit)
05    if hit.Parent:FindFirstChild('Dark4') then
06        humanoid = hit.Parent:FindFirstChild('Dark4').Humanoid
07            humanoid:TakeDamage(dmg)
08 
09        end
10    end)
0
You also need to make sure whatever you're hitting, I'm assuming a zombie... has the humanoid property in it. JayShepherdMD 147 — 5y
0
thanks, if the humanoid property is named Zombie do I change Humanoid to Zombie? zomspi 541 — 5y
0
Yes, and if there is a child in the Zombie Model named "Dark4" then keep it, but if it's not change both of them. If this works, please make sure to hit the button that lets everyone know I've answered your question. JayShepherdMD 147 — 5y
0
It still doesn't do damage though? zomspi 541 — 5y
View all comments (6 more)
0
I tested the classic sword and that does do damage, I tried to move my parts into the classic sword but my sword got flipped when I held it zomspi 541 — 5y
0
My script works perfectly, if it's not working that's a physical issue.. probably welding. Don't know why my answer was removed. JayShepherdMD 147 — 5y
0
It doesn't do damage to my entity or players zomspi 541 — 5y
0
https://vimeo.com/user104761799/review/370610144/2f5e936b26 this shows that it doesn't work zomspi 541 — 5y
0
Take a block, a part and insert the script I just said into it, then replace "Dark4" with Humanoid, remove ".Humanoid" and put dmg to 1. You will see that it works, then make my answer correct again! JayShepherdMD 147 — 5y
0
Yea, but it doesn't do any damage to my enemies! I am not trying to kill a block, also it isn't the enemy because the classic sword worked! zomspi 541 — 5y
Log in to vote
0
Answered by 5 years ago

ok now you got a solution. put this inside the sword tool

1script.Parent.Activated:Connect(function()
2script.Parent.Handle.Touched:Connect(function(hit)
3if hit.Parent.Name == script.Parent.Parent.Name then
4else hit.Parent.Humanoid.Health = 0
5end
6end)
7end)

Answer this question