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

Damage inflicting brick is not working?

Asked by
Primpy 25
7 years ago

Hello, ScriptingHelpers. I'm working on a Pokemon related game whose moves (tools) use bricks to inflict damage to the enemy. I'm trying to make a PvP / Non PvP thingy so if you don't want to fight, you can just disable PvP. However, there is something wrong with the script that is cloned in the bricks that are supposed to inflict damage.

wait(0.01)
damage = 0
omg = math.random(1, 10)
if omg == 1 then
    damage = 100
else damage = 50
end
humanoidnames = {"Humanoid"}
function onTouched(hit)
if hit.Parent.Name ~= script.Parent.Name then
if hit.Parent.Parent.Name ~= script.Parent.Name then

for i = 1 , #humanoidnames do
d = hit.Parent.Parent:findFirstChild(humanoidnames[i])
    player = d.Parent
    pvp = game.Players:findFirstChild(player.Name).stats.PvP
    if pvp.Value == 0 then damage = 0
if d ~= nil then
d.Health = d.Health - damage
script.Parent:Remove()
end
end

end
end
end
end
script.Parent.Touched:connect(onTouched)

These are the lines I added to the original script

    player = d.Parent
    pvp = game.Players:findFirstChild(player.Name).stats.PvP
    if pvp.Value == 0 then damage = 0

These lines are meant to make the player with PvP disabled take no damage from the brick. PvP is a value in stats, 1 means PvP Enabled and 0 means PvP Disabled.

For some reason, the script doesn't deal any damage to the enemy, even if the enemy has PvP enabled. There were no errors in the console, I just can't find the mistake.

Excuse me if the error is very small and/or stupid, I'm a mediocre scripter. Thanks :)

1 answer

Log in to vote
0
Answered by
Ocula 40
7 years ago
Edited 7 years ago

Hey, Primpy. The error here is at line 17. We want this conditional to end right after it sets the damage to 0, otherwise the script will only know to take damage when the PvP value is 0, but the damage is then set to 0 so it won't take damage.

Here's what you should change those lines to:

if pvp.Value == 0 then damage = 0 end
if d ~= nil then
    d.Health = d.Health - damage
    script.Parent:remove()
end

Paste that into lines, 17-21 and be sure to take out an extra end at the end of the function. Have a nice day!

Ocula

1
I'd also highly suggest to use indents in your code! It helps pinpoint issues with missing ends, etc. Ocula 40 — 7y
0
Thank you so much! And sorry for asking but what are indents? I'm a bit outdated when it comes to scripting, I don't know the new features (or if it's a new feature, I didn't know about it) Primpy 25 — 7y
0
Prefixing your code with TABs or spaces... Link150 1355 — 7y
0
Oh XD thanks :> Primpy 25 — 7y
Ad

Answer this question