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
4 years ago

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



if script.Parent.Blade.Touched == game.Workspace.Enemies.Dark4 then if script.Parent.CanDamage.Value == true then script.Parent.CanDamage.Value = false game.Workspace.Enemies.Dark4.Zombie.Health = game.Workspace.Enemies.Dark4.Zombie.Health - 100 else print("no") end end
0
for game.Workspace.Enemies.Dark4.Zombie.Health - 100 you did this - instead of this = oziase 1 — 4y
0
that was just a test, I am wanting to take like 20 health off of it zomspi 541 — 4y
0
It's not your sword script, it's a random person's sword script. We don't help with free code. hiimgoodpack 2009 — 4y
0
but it is mine? Line 2 and 3 are theirs the rest is mine zomspi 541 — 4y
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 — 4y

3 answers

Log in to vote
0
Answered by
Gingerely 245 Moderation Voter
4 years ago
Edited 4 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.

local enemies = game.Workspace.Enemies:GetChildren() --// All the children of the enemies folder.


for i, v in pairs(enemies) do
    if v:IsA("Model") then --// If the child is a model
        if v:FindFirstChild("Humanoid") then --// If the model has a humanoid
            wait(1)
            v.HumanoidRootPart.Touched:Connect(function() --// When the sword touches the npc
                v.Humanoid:TakeDamage(10) --// Npc takes 10 Damage
                wait(1)
            end)
        end
    end
    end

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

local enemies = game.Workspace.Enemies:GetChildren() --// All the children of the enemies folder.


for i, v in pairs(enemies) do
    if v:IsA("Model") then --// If the child is a model
        if v:FindFirstChild("Humanoid") then --// If the model has a humanoid
            wait(1)
            v.HumanoidRootPart.Touched:Connect(function()--// When the sword touches the npc
                script.Parent.Activated:Connect(function() --// If you click holding the sword it will damage.
                v.Humanoid:TakeDamage(10) --// Npc takes 10 Damage
                wait(1)
            end)
            end)
            end
    end
    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 — 4y
0
nvm I needed the rename something, thanks! zomspi 541 — 4y
Ad
Log in to vote
1
Answered by 4 years ago

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

local sword = script.Parent
local dmg = #ofdamageuwantswordtodo

sword.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild('Dark4') then
        humanoid = hit.Parent:FindFirstChild('Dark4').Humanoid
            humanoid:TakeDamage(dmg)

        end
    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 — 4y
0
thanks, if the humanoid property is named Zombie do I change Humanoid to Zombie? zomspi 541 — 4y
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 — 4y
0
It still doesn't do damage though? zomspi 541 — 4y
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 — 4y
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 — 4y
0
It doesn't do damage to my entity or players zomspi 541 — 4y
0
https://vimeo.com/user104761799/review/370610144/2f5e936b26 this shows that it doesn't work zomspi 541 — 4y
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 — 4y
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 — 4y
Log in to vote
0
Answered by 4 years ago

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

script.Parent.Activated:Connect(function()
script.Parent.Handle.Touched:Connect(function(hit)
if hit.Parent.Name == script.Parent.Parent.Name then
else hit.Parent.Humanoid.Health = 0
end
end)
end)

Answer this question