Pumpkin Script not working "TweenService"

Hello everyone! So today for my obby, I was trying to make a stage where pumpkins rotate 180 degrees. I have 18 pumpkins, and I didn’t want to have to script them one by one. So I tried to make a script where I could make it fast, and not have tween all of them 500 times. I am not really sure how to do this, but I tried and it didn’t work. Here is my script…

-- Variables
local TweenService = game:GetService("TweenService")
local pumps = {
	
	game.Workspace.pump1;
	game.Workspace.pump2;
	game.Workspace.pump3;
	game.Workspace.pump4;
	game.Workspace.pump5;
	game.Workspace.pump6;
	game.Workspace.pump7;
	game.Workspace.pump8;
	game.Workspace.pump9;
	game.Workspace.pump10;
	game.Workspace.pump11;
	game.Workspace.pump12;
	game.Workspace.pump13;
	game.Workspace.pump14;
	game.Workspace.pump15;
	game.Workspace.pump16;
	game.Workspace.pump17;
	game.Workspace.pump18
}
-- Main Code....
while true do
	wait()
	TweenService:Create(TweenInfo.new(1,Enum.EasingStyle.Back,Enum.EasingDirection.Out),            {pumps.CFrame * CFrame.Angles(math.rad(0), math.rad(180), math.rad(0))}):Play()
	wait(1)
	TweenService:Create(TweenInfo.new(1,Enum.EasingStyle.Back,Enum.EasingDirection.Out)             {pumps.CFrame * CFrame.Angles(math.rad(0), math.rad(-180), math.rad(0))}):Play()
	wait()
end

if you do know how to make these types of scripts shorter and to make them work, please let me know so I can use it in the future.

What error are you getting? The second TweenService:Create is missing a comma between 2nd and 3rd arguments.

Actually, it looks like there are only 2 arguments used in those Create functions. Isn’t there supposed to be an instance passed as the first arg? TweenService | Documentation - Roblox Creator Hub

1 Like

Heya, I dont have much experience with TweenService, specifically, but I would define these in a loop, that way you don’t have to define them all seperately.

-- Variables
local TweenService = game:GetService("TweenService")
local pumps = {}

--Make a reference to all the pumpkin objects into a table anyways, just so you dont have to keep going back to Workspace
for i = 1, 18 do 
        table.insert(pumps, game.Workspace["pump"..i])
end

-- Main Code....
while true do
	wait()
    for _,k in pairs (pumps) do
           TweenService:Create(k, TweenInfo.new(1, Enum.EasingStyle.Back,Enum.EasingDirection.Out), {k.CFrame * CFrame.Angles(math.rad(0), math.rad(180), math.rad(0))}):Play()
    end
	
	wait(1)

    for _,k in pairs (pumps) do
       TweenService:Create(k, TweenInfo.new(1,Enum.EasingStyle.Back,Enum.EasingDirection.Out),{k.CFrame * CFrame.Angles(math.rad(0), math.rad(-180), math.rad(0))}):Play()
    end
	
	wait()
end

Again, I’m not that familiar with TweenService, but this should get you closer to what you’re looking for!
This also fixes the issues that @Astr0Derp mentioned before.

2 Likes

For the tween, you have to make a variable like this:

local Tween = TweenService:Create(Your Stuff)

Then play the tween by the “Tween:Play” function (With your variable)

1 Like

Also for the pumpkins, put them in a folder and use :GetChildren (local pumps = PumpkinFolder:GetChildren()), this will create a table automatically.

2 Likes

It’s like my tween is nil or something like that.

Also it’s more organized :slight_smile:

1 Like
local pumps = game.Workspace:GetChildren("PumpkinFolder")

So something like this?

I think it was a good setup but, it says that it can’t find it in the dictionary.

It’s because you’re trying to change the CFrame of an array, which an array has no such index - doing Array.Index doesn’t change the property for all items within the array.
What you instead have to do is use a generic for and iterate through the array. TweenService:Create also takes the object to tween as its first input, just as a heads up.

for _, pump in ipairs(pumps) do -- Iterates through `pumps`
    TweenService:Create(pump, TweenInfo, Goal):Play(); -- Creates a new tween and plays it
end

Here, I have an example of a folder, in this case for pumpkins.
image

You have to use GetChildren() like that to easily create a table for your pumpkins:

local PumpkinTable = game.workspace.Pumpkins:GetChildren()

This is also better for your script performance. :slight_smile:

But I’m more kind of builder myself, I hope I still helped you though. :smile:

1 Like

I tried this

-- Variables
local TweenService = game:GetService("TweenService")
local PumpkinTable = game.Workspace.Pumpkins:GetChildren()
-- Main Code
local info = TweenInfo.new(1,Enum.EasingStyle.Back,Enum.EasingDirection.Out)

local turn = {CFrame * CFrame.Angles(math.rad(0), math.rad(180), math.rad(0))}
local Turn = {CFrame * CFrame.Angles(math.rad(0), math.rad(-180), math.rad(0))}

local tween = TweenService:Create(PumpkinTable,info,turn)
local Tween = TweenService:Create(PumpkinTable,info,Turn)

while true do
	wait()
	turn:Play()
	wait(1)
	Turn:Play()
	wait()
end

it’s not what you did, with the for loop, but I am not sure what I could be doing wrong with this. Should I try the for loop? And if I do, do I put it in the while loop?

Yeah, I recommend using the generic for loop - TweenService:Create doesn’t take an array, only the object itself.
For example

for _, Pumpkin in ipairs(Pumpkins) do
    local Turn = Pumpkin.CFrame * CFrame.Angles(0, math.pi, 0);
    TweenService:Create(Pumpkin, TweenInfo, {CFrame = Turn}):Play();
end

EDIT
You could put the generic for loop within the while loop, yes.

1 Like

ohhhh ok, also what does math.pi mean? I’m still pretty new to scripting.

math.pi is, well, pi or 3.14 (180 in radians).
EDIT
math.pi returns pi (3.14), it doesn’t return 180 - to convert it to degrees, you could use math.deg.

ohhhhhhhhhhhhhhhhhhhhhhh ok, so basically, it’s just a quicker way to say 180, or like when your doing for i = 0, 180, 0

1 Like

alright, I’ll test it out after class.

1 Like
local TweenService = game:GetService("TweenService")
local PumpkinTable = game.Workspace.Pumpkins:GetChildren()

local info = TweenInfo.new(1,Enum.EasingStyle.Back,Enum.EasingDirection.Out)

while true do
	for _,Pumpkin in ipairs(PumpkinTable) do
		local Turn = Pumpkin.CFrame * CFrame.Angles(0, math.pi, 0);
		TweenService:Create(Pumpkin, info, {CFrame = Turn}):Play();
		wait(1)
		for _,Pumpkin in ipairs(PumpkinTable) do
			local turn = Pumpkin.CFrame * CFrame.Angles(0, 180, 0)
			TweenService:Create(Pumpkin, info, {CFrame = turn}):Play()
		end
	end
end

I’m sure I did this wrong, I think what would help is if, you could actually make the script, and I could use it to see what I am doing wrong and what not.

It worked, thank you dude! thanks for all the help everyone!

2 Likes