TweenService giving error I can't figure out

Hey, so i’m trying make this little spaceship minigame prototype and you can turn on these head lights. But when you load up the game it automatically spits out a error saying:

‘‘TweenService:Create property named ‘Material’ cannot be tweened due to type mismatch (property is a ‘int’, but given type is ‘token’)’’.

This is at Line 13 of the code and I can’t figure out why its giving it so I’m hoping you guys can help me (also sorry if the variables or code is messy, I’m making this game just for fun so I don’t worry much about how the code looks :D)

local Light = script.Parent --This is a part/basepart
local TS = game:GetService("TweenService")
local TI = TweenInfo.new(1, Enum.EasingStyle.Exponential, Enum.EasingDirection.InOut, 0, false, 0)
local value = game.ReplicatedStorage.HeadlightsOnOff
local goalOn = {
	Material = Enum.Material.Neon
}

local goalOff = {
	Material = Enum.Material.Cobblestone
}

local TweenOn = TS:Create(Light, TI, goalOn)
local TweenOff = TS:Create(Light, TI, goalOff)

--the stuff below here dont matter but might as well add just in case
value.Changed:Connect(function()
	if value.Value == true then
		TweenOn:Play()
	else
		TweenOff:Play()
	end
end)

TweenService does need “numbers” to tween, so material cannot be tweened.

Can you tween materials at all? (i havent watched a tween service video in a while)

no materials can’t be tweened, colors can be though. just change the material directly instead

1 Like

No, tweening Material is not possible. You can interfere transparencies with textures to get a similar effect instead.

alright, thanks for replying though :smiley:

I already wasted 30 minutes on these head lights so i’ll just change them directly, thanks for the help though!

How exactly did you imagine Tweening a material would work? They’re essentially textures so there isn’t a range between two materials which you could tween between. If you need to toggle/loop through materials you can do so with any one of the available primitive loop constructs (for, while, repeat).

local part = script.Parent
local materials = {Enum.Material.SmoothPlastic, Enum.Material.Glass}

for _, material in ipairs(materials) do
	part.Material = material
	task.wait(0.5)
end