Well, i was working on a Planting Tool, i added the Tool, and a Localscript, it seemed to be fine but, i got a problem about GetChildren i'm almost a newbie to Lua Programming, anyways to fix this?
mouse = game.Players.LocalPlayer:GetMouse() mouse.Button1Down:connect(function() local Tree = game.ServerStorage.Tree.Tree1.GetChildren:Clone() Tree.Position = mouse.Hit.p Tree.Parent = game.Workspace wait(10) Tree.Tree1.GetChildren.Transparency = 1 Tree.Tree1.Tree2.GetChildren.Transparency = 0 wait(0.1) Tree.Tree1.Tree2.Leaf1.Transparency = 0.4 Tree.Tree2.Leaf2.Transparency = 0.4 wait(10) Tree.Tree1.Tree2.GetChildren.Transparency = 1 Tree.Tree1.Tree2.Tree3.GetChildren.Transparency = 0 wait(0.1) Tree.Tree1.Tree2.Tree3.Leave1.Transparency = 0.4 Tree.Tree1.Tree2.Tree3.Leave2.Transparency = 0.4 Tree.Tree1.Tree2.Tree3.Leave3.Transparency = 0.4 Tree.Tree1.Tree2.Tree3.Leave4.Transparency = 0.4 Tree.Tree1.Tree2.Tree3.Leave5.Transparency = 0.4 Tree.Tree1.Tree2.Tree3.Leave6.Transparency = 0.4 Tree.Tree1.Tree2.Tree3.Particle.Transparency = 0.4 Tree.Tree1.Tree2.Tree3.Particle.ParticleEmitter.Enabled = true end)
-- Note : I would be thankful if there is a way to add a delay too, like (* 20 *) seconds needed for the tool to be usable again, and also, here is the way i placed the models.
ServerStorage
-- Tree
---- Tree1
------ Tree2
-------- Tree3
-- Thank you for spending time and reading this.
You can simpy clone the Tree
model. The clone will contain cloned descendants aswell.
As for setting the transparency, use a for loop.
And to position it, use SetPrimaryPartCFrame()
function of the model, but first, set the PrimaryPart
property to the main part of the model in your properties window in studio.
Also, your script wouldn't work outside of studio due to how you use LocalPlayer and ServerStorage.
Here's a fixed FE compatible script:
Server script:
local event = Instance.new("RemoteEvent", game:GetService("ReplicatedStorage")) event.Name = "plantTree" local function SetTransparency(p, t) for i,v in pairs(p:GetChildren()) do if v:IsA"BasePart" then v.Transparency = t end end end event.OnServerEvent:Connect(function(plr, pos) local Tree = game.ServerStorage.Tree:Clone() Tree:SetPrimaryPartCFrame(pos) Tree.Parent = workspace wait(10) SetTransparency(Tree.Tree1, 1) SetTransparency(Tree.Tree1.Tree2, 0) wait(0.1) Tree.Tree1.Tree2.Leaf1.Transparency = 0.4 Tree.Tree2.Leaf2.Transparency = 0.4 wait(10) SetTransparency(Tree.Tree1.Tree2, 1) SetTransparency(Tree.Tree1.Tree2.Tree3, 0) wait(0.1) local tree3 = Tree:FindFirstChild("Tree3", true) for i,v in pairs(tree3:GetChildren()) do if v.Name:sub(1, 5) == "Leave" or v.Name == "Particle" then v.Transparency = 0.4 end end tree3.Particle.ParticleEmitter.Enabled = true end)
Local script:
local event = game:GetService("ReplicatedStorage"):WaitForChild("plantTree") local mouse = game.Players.LocalPlayer:GetMouse() mouse.Button1Down:connect(function() event:FireServer(CFrame.new(mouse.Hit.p)) end)
I believe I found your problem. GetChildren()
is a function, meaning you need to place brackets after you write it. So instead of
Tree.Tree1.Tree2.GetChildren.Transparency = 0
you need to have
Tree.Tree1.Tree2.GetChildren().Transparency = 0
However, GetChildren()
returns a table of objects, so it has no Transparency
property. To change the Transparency
of every item in the list, you need a for
loop:
local aList = Tree.Tree1.Tree2.GetChildren() for child in aList do child.Transparency = 0 end
I hope this answers your question, if no, tell me and I'll fix it my answer.