Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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.

0
that is not how you create a tween. use the normal way -_- cheslin23t 4 — 3y
0
link me to a website that says the normal way Baselistic 103 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

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!

0
When I call the module in the other script it automatically says that this is a part of the module. Baselistic 103 — 3y
Ad

Answer this question