Any way to do this faster?

So in my code here:

local cocao = script.Parent

local tweeningService = game:GetService("TweenService")
local tweenInfo =, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
local tweenProperties = {Size = cocao.StartSize.Value, Position = cocao.StartPos.Value}
local tween = tweeningService:Create(cocao,tweenInfo,tweenProperties)

local cocoaCollected = false
local cocoaAbleToCollect = true

local deb = false


cocao.Anchored = false

local function collectCocoa(hit)
	if not deb then
		deb = true
		local humanoid = hit.Parent:FindFirstChild("Humanoid")
		if humanoid ~= nil then
			local player = game.Players:GetPlayerFromCharacter(hit.Parent)
			local cocoaStat = player.leaderstats:WaitForChild("Cocoa")
			if cocoaStat ~= nil then
				if cocoaAbleToCollect then
					print("Made it to the collecting phase")
					cocoaStat.Value = cocoaStat.Value + (1 * player.Gamepasses.CocoaMultiplier.Value)
					cocoaCollected = true
					cocoaAbleToCollect = false
					cocao.Anchored = true
					cocao.Position = cocao.GrowPos.Value
					cocao.Size = cocao.GrowSize.Value
					cocao.Orientation = cocao.StartRotation.Value
					cocoaCollected = false
					cocoaAbleToCollect = true
					cocao.Anchored = false
					deb = false
				warn("No cocoa stat found")
				deb = false
			deb = false


When the cocoa is touched it starts to grow again. BUT… the Size/Position is a value that’s in the cocoa, and every time I make a duplicate I have to go in and do the same steps over and over again and now I just don’t want to do that.

Here is the explorer view:

If you need more info tell me!


As for your problem one way of making a fix would be to have a ServerScriptService script which will get all of the descendants of Workspace, and then anything with the name “Cocoa” will be given the Script “System” and the five Values which would be stored in ReplicatedStorage. Please let me know of any issues! Sorry if this didn’t help.

some code edits I recommend

Instead you could do

local plr = Players:GetPlayerFromCharacter(hit.Parent)
if plr then
-- code

Also your deb variables outside of the if statement will instantly turn to false as theirs no wait(), you should make deb true if the cocoaStat ~= nil

I don’t think this would help at all with changing the values:

To what they should be, every single time I duplicate the tree.

I am confused, what do you mean “every single time I duplicate the tree”. Could you explain in more detail what is happening? I assumed you were Setting the grown cocoas position to the old cocoa position?

When I tween the object, the position/size goes to the Vector3 values for the growing position/size.

So every time I duplicate a cocoa tree and move it somewhere else, I have to go in every single cocoa in that tree and set the values to something else.

What I’m asking for is a faster way to do that, like automatically changing the value in the script/command bar.

Still don’t have a solution, I really need one!