Hello, I made a script to damage players in a radius around a pet.
Now I want to check to see if a player is on their team before damaging them and I plan to make the healing pet the same way in reverse.
The problem is that when I try to check for a team member the script totally breaks and doesn’t damage anything or have an error message.
The three teams are Pithons, Algebros, and Mathletes.
Here is a portion of the original script, the rest is just adjustments based on player level:
local cloud = script.Parent
local ownername = ""
local char = script.Parent.Parent.Parent.Parent
local plr = game.Players:GetPlayerFromCharacter(char)
local level = plr.leaderstats.Level.Value
if level >= 27 and level < 29 then
while true do
for i, v in pairs(game.Players:GetPlayers()) do
if v.Name == ownername then return end
local hrp = v.Character:FindFirstChild('HumanoidRootPart')
if hrp then
local dist = (cloud.Position - hrp.Position).Magnitude
if dist < 10 and script.Parent.Parent.Parent.Parent ~= hrp.Parent then -- in studs
if hrp.Parent.Humanoid.Health > 1 then
hrp.Parent.Humanoid.Health = hrp.Parent.Humanoid.Health - 1-- do damage here
end
end
end
end
wait(.1)
end
end
Here is what I added to try to get it to identify teams:
local cloud = script.Parent
local ownername = ""
local char = script.Parent.Parent.Parent.Parent
local plr = game.Players:GetPlayerFromCharacter(char)
local level = plr.leaderstats.Level.Value
if level >= 27 and level < 29 then
while true do
if plr.Team == "Algebros" then
for i, v in pairs(game.Teams.Mathletes:GetPlayers()) do
if v.Name == ownername then return end
local hrp = v.Character:FindFirstChild('HumanoidRootPart')
if hrp then
local dist = (cloud.Position - hrp.Position).Magnitude
if dist < 10 and script.Parent.Parent.Parent.Parent ~= hrp.Parent then -- in studs
if hrp.Parent.Humanoid.Health > 1 then
hrp.Parent.Humanoid.Health = hrp.Parent.Humanoid.Health - 1-- do damage here
end
end
end
end
for i, v in pairs(game.Teams.Pithons:GetPlayers()) do
if v.Name == ownername then return end
local hrp = v.Character:FindFirstChild('HumanoidRootPart')
if hrp then
local dist = (cloud.Position - hrp.Position).Magnitude
if dist < 10 and script.Parent.Parent.Parent.Parent ~= hrp.Parent then -- in studs
if hrp.Parent.Humanoid.Health > 1 then
hrp.Parent.Humanoid.Health = hrp.Parent.Humanoid.Health - 1-- do damage here
end
end
end
end
elseif plr.Team == "Mathletes" then
for i, v in pairs(game.Teams.Algebros:GetPlayers()) do
if v.Name == ownername then return end
local hrp = v.Character:FindFirstChild('HumanoidRootPart')
if hrp then
local dist = (cloud.Position - hrp.Position).Magnitude
if dist < 10 and script.Parent.Parent.Parent.Parent ~= hrp.Parent then -- in studs
if hrp.Parent.Humanoid.Health > 1 then
hrp.Parent.Humanoid.Health = hrp.Parent.Humanoid.Health - 1-- do damage here
end
end
end
end
for i, v in pairs(game.Teams.Pithons:GetPlayers()) do
if v.Name == ownername then return end
local hrp = v.Character:FindFirstChild('HumanoidRootPart')
if hrp then
local dist = (cloud.Position - hrp.Position).Magnitude
if dist < 10 and script.Parent.Parent.Parent.Parent ~= hrp.Parent then -- in studs
if hrp.Parent.Humanoid.Health > 1 then
hrp.Parent.Humanoid.Health = hrp.Parent.Humanoid.Health - 1-- do damage here
end
end
end
end
elseif plr.Team == "Pithons" then
for i, v in pairs(game.Teams.Algebros:GetPlayers()) do
if v.Name == ownername then return end
local hrp = v.Character:FindFirstChild('HumanoidRootPart')
if hrp then
local dist = (cloud.Position - hrp.Position).Magnitude
if dist < 10 and script.Parent.Parent.Parent.Parent ~= hrp.Parent then -- in studs
if hrp.Parent.Humanoid.Health > 1 then
hrp.Parent.Humanoid.Health = hrp.Parent.Humanoid.Health - 1-- do damage here
end
end
end
end
for i, v in pairs(game.Teams.Mathletes:GetPlayers()) do
if v.Name == ownername then return end
local hrp = v.Character:FindFirstChild('HumanoidRootPart')
if hrp then
local dist = (cloud.Position - hrp.Position).Magnitude
if dist < 10 and script.Parent.Parent.Parent.Parent ~= hrp.Parent then -- in studs
if hrp.Parent.Humanoid.Health > 1 then
hrp.Parent.Humanoid.Health = hrp.Parent.Humanoid.Health - 1-- do damage here
end
end
end
end
end
wait(.1)
end
end
I also tried changing “if v.Name == owernname then return end” to “if v.Team == Mathletes then retrun end” but nothing works. I’m sure there is an easier way to do this because it took a 100 line script and made it into 750 lines…