TweenService not working inside ModuleScript

I wrote 2 scripts, the first script contains the animation logic and the second script contains the animation launch. The problem is that none of this works and I don’t understand why.

--ModuleScript
local animationButtons = {}

local startGameButton=game:GetService("StarterGui"):WaitForChild("MainMenu"):WaitForChild("StartGameButton")
local settingsGameButton=game:GetService("StarterGui"):WaitForChild("MainMenu"):WaitForChild("SettingsGameButton")
local devlogButton=game:GetService("StarterGui"):WaitForChild("MainMenu"):WaitForChild("DevlogButton")

local tween=game:GetService("TweenService")
local tweenI=TweenInfo.new(
	2,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)

function animationButtons.Position(button,position,play)
	local tweenPlay=tween:Create(button,tweenI,{Position=position})
	if play==true then
		tweenPlay:Play()
	end
end

return animationButtons
--LocalScript
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local moduleScript = require(game:GetService("ReplicatedStorage"):WaitForChild("ClicksPlayerCountModule"))
local moduleScript2 = require(game:GetService("ReplicatedStorage"):WaitForChild("ClicksPlayerCountModule"):WaitForChild("ButtonsAnimationModule"))

local startGameButton=game:GetService("StarterGui"):WaitForChild("MainMenu"):WaitForChild("StartGameButton")
local settingsGameButton=game:GetService("StarterGui"):WaitForChild("MainMenu"):WaitForChild("SettingsGameButton")
local devlogButton=game:GetService("StarterGui"):WaitForChild("MainMenu"):WaitForChild("DevlogButton")

mouse.Button1Up:Connect(function()
	print("1")
	moduleScript2.Position(startGameButton, UDim2.new(0.267, 0, 0.332, 0),true)
end)

Can you post what the output looks like when you try to run the code?

There are no messages in the console related to a modular or local script.

maybe try only structuring and returning the tween from the module, then play the tween directly from the client

I’ll try, but I don’t think it can work.

GOT you buddy!

In this local script you are referencing to objects inside StarterGui,
And when a player joins, the Actual Gui That is displayed on screen is copied from StarterGui and to that players PlayerGui folder, you are actually tweeting stuff that is inside the StarterGui, not the actual PlayerGui inside your local player (That is rendered on screen). So you may want to hold reference to the GuiButtons and objects inside your LocalPlayer.PlayerGui folder.

1 Like

Thank you. I always confuse it. Now I will try your answer.

you may wanna do like:

local startGameButton = game:GetService("Players").LocalPlayer.PlayerGui:WaitForChild("MainMenu"):WaitForChild("StartGameButton")

something like this,
also you are using game:GetService() function every time, you can create a variable and store result of it in eg: game:GetService("Players"), it will hold reference to players service,
then you can: Players.LocalPlayer.PlayerGui:WaitForChild("MainMenu"):WaitForChild("StartGameButton")
but to optimize it more you can just directly set reference to LocalPlayer’s PlayerGui by:

local Players = game:GetService("Players")
local PlayerGUI= Players.LocalPlayer.PlayerGui

local startGameButton = PlayerGUI:WaitForChild("MainMenu"):WaitForChild("StartGameButton")
1 Like

It worked. Thank you.

P.S. As for optimization, I know that my method is not very good, but I program for myself, so I don’t care about performance.

1 Like

But at the very end, you are making a game on roblox, and you may want it to be optmised so your player base doesn’t get upset due to lack of optimizations causing lag in game.

I know. But I don’t want to get carried away with excessive productivity yet.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.