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