Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why is my tween module for my button system not working?

Hello! So, I am trying to make a button system via Attributes feature. But, the tween is not working, I made sure the properties and attributes are right. I debugged via print() and made sure everything is working. (What I'm trying to do is make the crystal be white when touched.)

Here is the script:

local crystal = script.Parent
local OutputON = crystal:GetAttribute("OutputON")
local moduleSc = require(game.ReplicatedStorage.ModuleScript)

crystal.Touched:Connect(function(h)
	if h.Parent:FindFirstChild("Humanoid") then
		crystal:SetAttribute("OutputON", true)
		local OutputON = crystal:GetAttribute("OutputON")
		moduleSc.crystalTurnOn(OutputON,crystal)
	end
end)

Here is the module script:

local module = {}
local ts = game:GetService("TweenService")
module.crystalTurnOn = function(attribute,part)
	if attribute == true then
		local tweenInfo = TweenInfo.new(
			7,
			Enum.EasingStyle.Linear,
			Enum.EasingDirection.In,
			1,
			false,
			5
		)
		local tween = ts:Create(part,tweenInfo,{Color = Color3.fromRGB(255, 255, 255)})
		tween:Play()
	end
end
return module

Any help appreciated.

2 comments

0

that is not how you create a tween. use the normal way -_-

0

link me to a website that says the normal way

1 answer

The only error is that you are returning an empty table when you call the module!

local module = {} -- empty table
local ts = game:GetService("TweenService")
module.crystalTurnOn = function(attribute,part) --calling an nil module and function 
    if attribute == true then
        local tweenInfo = TweenInfo.new(
            7,
            Enum.EasingStyle.Linear,
            Enum.EasingDirection.In,
            1,
            false,
            5
        )
        local tween = ts:Create(part,tweenInfo,{Color = Color3.fromRGB(255, 255, 255)})
        tween:Play()
    end
end
return module -- returning the empty module 

Here's how it should look.

local ts = game:GetService("TweenService")
crystalTurnOn = function(attribute,part)
    if attribute == true then
        local tweenInfo = TweenInfo.new(
            7,
            Enum.EasingStyle.Linear,
            Enum.EasingDirection.In,
            1,
            false,
            5
        )
        local tween = ts:Create(part,tweenInfo,{Color = Color3.fromRGB(255, 255, 255)})
        tween:Play()
    end
end
return crystalTurnOn 

Also, I'm not sure if you can tween a Color3. Good luck!

1 comment

0

When I call the module in the other script it automatically says that this is a part of the module.

This discussion is preserved as it was. New answers, comments, and votes are closed.