local players = game:GetService("Players")
while task.wait() do
if game.Workspace.HealthPack then
local touching = game.Workspace:GetPartsInPart(script.Parent)
for i, v in pairs(touching) do
if v.Parent:FindFirstChild("Humanoid") ~= nil then
local playerFromCharacter = players:GetPlayerFromCharacter(v)
if playerFromCharacter.TeamColor.Color == game.Workspace.HealthPack.circle.Color then
v.Parent:FindFirstChild("Humanoid").Health = v.Parent:FindFirstChild("Humanoid").Health + 1.25
wait(0.03)
end
end
end
end
end
keeps giving me the Attempt to index nil with ‘TeamColor’ error.
I have tried to check some other articles using the if not player then return code but it didn’t give me a error or anything, so am unsure on how to fix it.
local players = game:GetService("Players")
while task.wait() do
if game.Workspace.HealthPack then
local touching = game.Workspace:GetPartsInPart(script.Parent)
for i, v in pairs(touching) do
if v.Parent:FindFirstChild("Humanoid") ~= nil then
local playerFromCharacter = players:GetPlayerFromCharacter(v)
if playerFromCharacter.TeamColor.Color == game.Workspace.HealthPack.circle.BrickColor then -- BrickColor instead of Color
v.Parent:FindFirstChild("Humanoid").Health = v.Parent:FindFirstChild("Humanoid").Health + 1.25
wait(0.03)
end
end
end
end
end
--//Services
local Players = game:GetService("Players")
--//Loops
while task.wait() do
local touching = workspace:GetPartsInPart(script.Parent)
for i, part in pairs(touching) do
local player = Players:GetPlayerFromCharacter(part.Parent)
local character = player and player.Character
local humanoid = character and character:FindFirstChildWhichIsA("Humanoid")
if humanoid and player.TeamColor.Color == workspace.HealthPack.circle.Color then
humanoid.Health += 1.25
task.wait(0.03)
end
end
end
Because you put v instead of v.Parent as the parameter. Instead of putting the character as the parameter, you put a part inside the character, which will always return false
It’s kind of weird as theres a ability where it spawns in a heal field from server storage. The ability script is in StarterCharacterScripts and when the player uses the keyblind it will spawn the heal field using a remote event
It could be a problem with referencing the team color.
Try this:
--//Services
local Players = game:GetService("Players")
--//Loops
while task.wait() do
local touching = workspace:GetPartsInPart(script.Parent)
for i, part in pairs(touching) do
local player = Players:GetPlayerFromCharacter(part.Parent)
local character = player and player.Character
local humanoid = character and character:FindFirstChildWhichIsA("Humanoid")
print(script.Parent.Parent.circle.Color) --//Delete if it works after testing
if humanoid and player.TeamColor.Color == script.Parent.Parent.circle.Color then
humanoid.Health += 1.25
task.wait(0.03)
end
end
end
Oh I think I found out the problem. You did player.TeamColor.Color which gives the RGB value, not the BrickColor value.
Try this:
--//Services
local Players = game:GetService("Players")
--//Loops
while task.wait() do
local touching = workspace:GetPartsInPart(script.Parent)
for i, part in pairs(touching) do
local player = Players:GetPlayerFromCharacter(part.Parent)
local character = player and player.Character
local humanoid = character and character:FindFirstChildWhichIsA("Humanoid")
if humanoid and player.TeamColor == script.Parent.Parent.circle.Color then
humanoid.Health += 1.25
task.wait(0.03)
end
end
end
Also, if you could send a .rbxm file with the healthpack, I could help out much quicker.