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 :)

4 comments
I'd also highly suggest to use indents in your code! It helps pinpoint issues with missing ends, etc.
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)
Prefixing your code with TABs or spaces...
Oh XD thanks :>