this is a continuation of my previous question but with a different question, so what im trying to do is to call descendants the have the tag “Grow” which is all inside a Prompt and do stuff with it, but there is another script which find if the descendants of “Plants” are a union operation
(There are two scripts, a Local script inside a tool and a regular one inside server script)
it works for two or one of the plants there (for example back and starter) but it completely broke for the others, no error on the output
i believe it’s called yielding? not super familiar with it so i had no idea how to fix it
the original set of scripts
Server Script
local plants = workspace.Plants
local tree = game:GetService("ReplicatedStorage").Tree
local event = game.ReplicatedStorage.Event:WaitForChild("Tree")
local ts = game:GetService("TweenService")
local goal = {}
goal.Transparency = 0.5
goal.Size = Vector3.new(30, 30, 30)
for i, v in ipairs(plants:GetDescendants()) do
if v:IsA("UnionOperation") then
local sz = v.Safezone
local dirtpos = v:GetAttribute("Pivot")
local tinfo = TweenInfo.new(5)
local tween = ts:Create(sz, tinfo, goal)
sz.Transparency = 1
v.Prompt.Triggered:Connect(function()
v.Prompt:Destroy()
v.Tree:Destroy()
tween:Play()
local cloned = tree:Clone()
cloned.Parent = v.Parent.Trees
cloned:PivotTo(dirtpos)
end)
end
end
Local Script
local plants = workspace.Plants
local water = script.Parent.Water.Particle
local currentnum = game.Players.TotalPlant
local event = game.ReplicatedStorage.Event:WaitForChild("Tree")
water.Enabled = false
for i, v in ipairs(plants:GetDescendants()) do
if v:HasTag("Grow") then
v.Enabled = false
script.Parent.Equipped:Connect(function()
v.Enabled = true
v.Triggered:Connect(function()
event:Fire()
v:Destroy()
water.Enabled = true
wait(3)
currentnum.Value += math.clamp(1,1,1)
water.Enabled = false
end)
end)
script.Parent.Unequipped:Connect(function()
v.Enabled = false
end)
end
end
btw the math clamp is my attempt to make the value not doubled, it works fairly ok lol
my attempt of using an event (does not work)
Server Script
local plants = workspace.Plants
local tree = game:GetService("ReplicatedStorage").Tree
local event = game.ReplicatedStorage.Event:WaitForChild("Tree")
local ts = game:GetService("TweenService")
local tinfo = TweenInfo.new(5)
local goal = {}
goal.Transparency = 0.5
goal.Size = Vector3.new(30, 30, 30)
for i, v in ipairs(plants:GetDescendants()) do
if v:IsA("UnionOperation") then
local sz = v.Safezone
local dirtpos = v:GetAttribute("Pivot")
local tween = ts:Create(sz, tinfo, goal)
sz.Transparency = 1
local function cool()
v.Prompt:Destroy()
v.Tree:Destroy()
tween:Play()
local cloned = tree:Clone()
cloned.Parent = v.Parent.Trees
cloned:PivotTo(dirtpos)
end
event.Event:Connect(cool)
end
end
Local Script
local plants = workspace.Plants
local water = script.Parent.Water.Particle
local currentnum = game.Players.TotalPlant
local event = game.ReplicatedStorage.Event:WaitForChild("Tree")
water.Enabled = false
for i, v in ipairs(plants:GetDescendants()) do
if v:HasTag("Grow") then
v.Enabled = false
script.Parent.Equipped:Connect(function()
v.Enabled = true
v.Triggered:Connect(function()
event:Fire()
v:Destroy()
water.Enabled = true
wait(3)
currentnum.Value += math.clamp(1,1,1)
water.Enabled = false
end)
end)
script.Parent.Unequipped:Connect(function()
v.Enabled = false
end)
end
end
here is my hierarchy, the unions all had the same childrens
again, Grow tag is inside Prompt
so yeah, i would appreciate any help like always im kinda stuck here lol
edit :
i provided a simpler version of the game’s file for testing here