So the issue is that the script output shows no errors when executed, but yet a part of the script is not working. I cannot seem to find out why and have been trying to figure out myself by messing around with it, but it’s no use.
When the player’s TeamColor is “Bright blue” and the player walks into the region, the region part does not change to a blue color or tween. However, I know the script itself is working because this function is the first called in a series of functions including a function that adds points, and the points are being added. If any more information is needed, then I’d gladly provide it.
Here’s the code:
function regionVisualEffect()
game:GetService("Players").PlayerAdded:Connect(function(Player)
if Player.TeamColor == "Bright blue" then
regionVisual.Transparency = 0
regionVisual.Color = Color3.fromRGB(0,0,255)
tween:Create(regionVisual,TweenInfo.new(1),{Transparency = .9}):Play()
elseif #playerInBounds > 1 then
regionVisual.Transparency = 0
regionVisual.Color = Color3.fromRGB(255,255,255)
tween:Create(regionVisual,TweenInfo.new(1),{Transparency = .9}):Play()
end
end)
end
Yes, the part I showed is just a small part of a larger code written in a script. If I replace ‘Player.TeamColor == “Bright blue”’ with ‘#playerInBounds == 1’, it works perfect. Not sure why it isn’t working with the first part.
local point1 = script.Parent.Parent.CapturePoints.Point1
local point2 = script.Parent.Parent.CapturePoints.Point2
point1.Transparency = 1
point2.Transparency = 1
local region = Region3.new(point1.Position,point2.Position)
local regionVisual = Instance.new("Part")
regionVisual.Size = region.Size
regionVisual.CFrame = region.CFrame
regionVisual.Anchored = true
regionVisual.CanCollide = false
regionVisual.Transparency = .9
regionVisual.Material = Enum.Material.ForceField
regionVisual.TopSurface = Enum.SurfaceType.Smooth
regionVisual.BottomSurface = Enum.SurfaceType.Smooth
regionVisual.Parent = script.Parent.Parent.CapturePoints
local ignoreList = {point1,point2,regionVisual}
local playerInBounds = {}
local tween = game:GetService("TweenService")
function checkForNewPlayers()
for _,part in ipairs(partsInRegion) do
local player = game.Players:GetPlayerFromCharacter(part.Parent)
if player then
if not table.find(playerInBounds,player) then
if player.Character.Humanoid.Health > 0 then
table.insert(playerInBounds,player)
end
end
end
end
end
function removeOldPlayers()
for playerIndex,player in ipairs (playerInBounds) do
for partIndex,part in ipairs (partsInRegion) do
if player == game.Players:GetPlayerFromCharacter(part.Parent) then
if player.Character.Humanoid.Health > 0 then
break
else
table.remove(playerInBounds,playerIndex)
break
end
elseif partIndex == #partsInRegion then
table.remove(playerInBounds,playerIndex)
end
end
end
end
function addPoints()
if #playerInBounds == 1 then
local points = playerInBounds[1].leaderstats.Points
points.Value = points.Value + 1
end
end
function regionVisualEffect()
game:GetService("Players").PlayerAdded:Connect(function(Player)
if Player.TeamColor == "Bright blue" then
regionVisual.Transparency = 0
regionVisual.Color = Color3.fromRGB(0,0,255)
tween:Create(regionVisual,TweenInfo.new(1),{Transparency = .9}):Play()
elseif #playerInBounds > 1 then
regionVisual.Transparency = 0
regionVisual.Color = Color3.fromRGB(255,255,255)
tween:Create(regionVisual,TweenInfo.new(1),{Transparency = .9}):Play()
end
end)
end
while wait(1) do
partsInRegion = workspace:FindPartsInRegion3WithIgnoreList(region,ignoreList,math.huge)
removeOldPlayers()
checkForNewPlayers()
addPoints()
regionVisualEffect()
end
So basically the script uses region3 to tell whether or not players are in the given part. The issue is the function regionVisualEffect() because the region visual effect is not working despite no errors occurring. If I replace ‘if Player.TeamColor == “Bright blue” then’ with ‘if #playerInBounds == 1 then’, the script works perfectly and shows the region visual effect. I don’t understand why the visual effect is not showing if I replace the latter with Player.TeamColor == “Bright blue”.
Maybe it does not solve the problem but I would recommend using Print () in specific places to see how far the code goes and with the same print () see the values of the variables with that you will see how far the code goes and have an idea of how to repair it
since the only one who knows the purpose and functions of each variable is you and since it is not a “generic” script it is hard to understand
local parts = workspace:FindPartsInRegion3WithIgnoreList(region, ignoreList)
for _, v in pairs(parts) do
local humanoid = v:FindFirstAncestorWhichIsA("Model"):FindFirstChildOfClass("Humanoid") or v.Parent:FindFirstAncestorWhichIsA("Model"):FindFirstChildOfClass("Humanoid")
local player = humanoid and game:GetService("Players"):GetPlayerFromCharacter(humanoid.Parent)
if player and not alreadyCounted[player.UserId] then
alreadyCounted[player.UserId] = true
player.leaderstats.Points.Value = player.leaderstats.Points.Value + 1
end
end