tree1 = workspace.TREES
print("test")
local tree = tree1:FindFirstChild("treething") -- not sure what to do rather than findfirstchild without it breaking
while true do wait(2) local distance1 = 20 local distance3 = 50 local lowpoly = tree.LowPoly for i, v in pairs(workspace:GetChildren()) do if v:FindFirstChild('Humanoid') then if game.Players:FindFirstChild(v.Name) then if (v.HumanoidRootPart.Position - tree.Trunk.Position).Magnitude > distance1 then print("trunk invisible")
tree.Trunk.Transparency = 0 -- wanting this to do this to multiple trunks not just one --lowpoly.Leaves.Transparency = 1 --lowpoly.Trunk.Transparency = 1 end if (v.HumanoidRootPart.Position - tree.Trunk.Position).Magnitude > distance3 then print("trunk visible") tree.Trunk.Transparency = 1 --lowpoly.Leaves.Transparency = 0.05 --lowpoly.Trunk.Transparency = 0 end end end end
end
I am not a very good scripter, but I think you should use :GetDescendants('trunk') instead of findfirstchild('trunk'). That way you can group all the trees together and just get the trunk.
Heres a sample code i havent tested it and im not 100% sure it will work sorry:
local trunk = game.workspace.trees:GetDescendants('trunk')
trunk.transparency = 1
Now if you want to get the position of your trunk you could use this, this code could help! note i havent tested it!
local trunk = game.workspace.trees:GetDescendants('trunk') local trunknum = #trunk for i = 1,trunknum do local num = trunk[i] if num.Name == 'trunk' then num.Transparency = 1 local trunkposition = num.Position -- there might be something to do with vector3 if it cant print out the position i think so you can also use num.CFrame print(trunkposition) end end
If you want it for it to change tranparency within a certain distance i have tested this!
local trunk = game.workspace.trees:GetDescendants('trunk') local trunknum = #trunk local distance3 = 50 for i = 1,trunknum do wait(5) local num = trunk[i] if num.Name == 'trunk' then num.Transparency = 1 local trunkposition = num.Position -- there might be something to do with vector3 if it cant print out the position i think so you can also use num.CFrame print(trunkposition) for i, v in pairs(workspace:GetChildren()) do if v:FindFirstChild('Humanoid') then if (v.HumanoidRootPart.Position - num.Position).Magnitude > distance3 then print("its visible now") num.Transparency = 0 else print("Not in range") num.Transparency = 1 end end end end end