Hvxbyte
|
  |
| Joined: 19 Aug 2015 |
| Total Posts: 410 |
|
|
| 29 Aug 2015 09:23 AM |
Obviously not the best code ever, but basically, there's territories, and each territory has a part (fog of war), but I want to get the touching parts of YOUR territories, and destroy the fog of war part.
No errors, but nor does it work.
local player = game.Players.LocalPlayer
local map = script.Parent
for _, country in next, map:GetChildren() do if country:IsA("Model") then for _, territory in next, country:GetChildren() do if territory:IsA("Part") then territory.Changed:connect(function(BrickColor) if BrickColor == BrickColor.new(player.TeamColor.Name) then for _, connectedPart in next, territory:GetTouchingParts() do if connectedPart.Name == "Territory" then connectedPart:FindFirstChild("Fog of War"):Destroy() end end end end) end end end end
|
|
|
| Report Abuse |
|
|
Hvxbyte
|
  |
| Joined: 19 Aug 2015 |
| Total Posts: 410 |
|
|
| 29 Aug 2015 09:25 AM |
Just to break it down a little.
function fogOfWar(part) for _, connectedPart in next, part:GetTouchignParts() do if connectedPart.Name == "Territory" then connectedPart:FindFirstChild("Fog of War"):Destroy() end end end
for _, country in next, map:GetChildren() do if country:IsA("Model") then for _, territory in next, country:GetChildren() do if territory:IsA("Part") then territory.Changed:connect(function(BrickColor) if BrickColor == BrickColor.new(player.TeamColor.Name) then fogOfWar(territory) end end) end end end end
|
|
|
| Report Abuse |
|
|
patzit
|
  |
| Joined: 23 Mar 2010 |
| Total Posts: 42 |
|
|
| 29 Aug 2015 09:57 AM |
Notice that GetTouchingParts only returns parts that intersect the part you call it on, not adjacent ones. If this is the problem then try to increase the size of your "Fog of war" bricks to intersect your "territory" parts.
|
|
|
| Report Abuse |
|
|
Hvxbyte
|
  |
| Joined: 19 Aug 2015 |
| Total Posts: 410 |
|
| |
|
Hvxbyte
|
  |
| Joined: 19 Aug 2015 |
| Total Posts: 410 |
|
|
| 29 Aug 2015 10:07 AM |
| I've temporarily removed the conditional statement and replace it with print(connectedPart.Name)... doesn't seem to work. |
|
|
| Report Abuse |
|
|
Hvxbyte
|
  |
| Joined: 19 Aug 2015 |
| Total Posts: 410 |
|
|
| 29 Aug 2015 08:52 PM |
Bump, updated code-ish. Tried to use a repeat loop to see if it wasn't working the first time around, still no luck. Am I doing something wrong?
local player = game.Players.LocalPlayer
local activeMap = game.Workspace:FindFirstChild("Active Map")
function fogOfWar(part) part.Changed:connect(function(property) if property == "BrickColor" then if property == player.TeamColor then for _, connected in next, part:GetTouchingParts() do if connected.Name == "Fog of War" then connected:Destroy() end end end end end) end
repeat wait() for _, map in next, activeMap:GetChildren() do if map:IsA("Model") then for _, country in next, map:GetChildren() do if country:IsA("Model") then for _, territory in next, country:GetChildren() do if territory:IsA("Part") then fogOfWar(territory) end end end end end end until player == nil |
|
|
| Report Abuse |
|
|