You can write your topic however you want, but you need to answer these questions:
-
Hi there! I am trying to make a custom health bar for my game.
-
For some reason, an error keeps being returned (see in bold below).
-
I have looked everywhere, even followed a tutorial. Still no luck.
The script used to work, I don’t know whether there has been a recent Roblox Studio update or if Roblox is acting weird at the moment, but it was working 2 days ago for sure. The script is a normal script inside of StarterCharacterScripts and the player
variable is located at StarterPlayer
SCRIPT
local Teams = game:GetService("Teams")
local TweenService = game:GetService("TweenService")
local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent.Parent.Parent.Parent)
local meter = script.Parent
local groupId = ""
while wait() do
local rainbowColors = {
Color3.fromRGB(255, 0, 0), -- red
Color3.fromRGB(255, 127, 0), -- orange
Color3.fromRGB(255, 255, 0), -- yellow
Color3.fromRGB(0, 255, 0), -- green
Color3.fromRGB(0, 0, 255), -- blue
Color3.fromRGB(148, 0, 211) -- purple
}
local orangeColors = {
Color3.fromRGB(236, 172, 94),
Color3.fromRGB(236, 120, 4),
Color3.fromRGB(207, 108, 9),
Color3.fromRGB(172, 92, 13),
Color3.fromRGB(207, 108, 9),
Color3.fromRGB(236, 120, 4)
}
local blueColors = {
Color3.fromRGB(126, 174, 250),
Color3.fromRGB(4, 175, 236),
Color3.fromRGB(9, 137, 207),
Color3.fromRGB(13, 105, 172),
Color3.fromRGB(9, 137, 207),
Color3.fromRGB(4, 175, 236)
}
if player.Team == Teams.Host then
for i = 1, #rainbowColors do
local nextColor = rainbowColors[i]
local tweenInfo = TweenInfo.new(0.5) -- adjust duration as needed
local tween = TweenService:Create(meter, tweenInfo, {
BackgroundColor3 = nextColor
})
tween:Play()
tween.Completed:Wait()
end
elseif player.Team == Teams["Lobby Duty"] then
for i = 1, #blueColors do
local nextColor = blueColors[i]
local tweenInfo = TweenInfo.new(0.5) -- adjust duration as needed
local tween = TweenService:Create(meter, tweenInfo, {
BackgroundColor3 = nextColor
})
tween:Play()
tween.Completed:Wait()
end
else
meter.BackgroundColor3 = Color3.fromRGB(0, 255, 0)
end
end
ERROR
08:53:42.215 Workspace.greeninja_97.HealthScript.Health.Meter.ColorChange:83: attempt to index nil with 'Team' - Server - ColorChange:83
08:53:42.216 Script 'Workspace.greeninja_97.HealthScript.Health.Meter.ColorChange', Line 83 - Studio - ColorChange:83