Is there a way to tween materials?

so i was wondering if there is a way to tween material so like it dosent change instant but it goes from neon to metal slowly i mean tweening, you know.

4 Likes

Why don’t you experiment? I’ve never tried, but I’m guessing no

what do you mean by experiment?, i cant try if i dont know how to.

tweening would be going from a certain value to another value, for materials, there isnt anything in between so it wouldnt really be possible, what you could do is have 2 parts of different materials and have one fully visible then make them switch

metal - visible → invisible
neon - invisible → visible

something like that might work
using a tween of course to make them invisible/visible

10 Likes

well as u said it its the only way so i guess its the way to do it, thanks :smiley: , but i have no idea how to tween a value.

1 Like

yay my first solution :smiley: no problem, but maybe look into it a bit more you might find a way, unless the way i explained is fine with what you need

1 Like

yeah, maybe it will take 2 parts more but who care beside real fried potato pc after all…

1 Like

my bad didnt see the end, to tween a value such as the transparency
id have to go check in my game since i do not remember fully how to tween, but you could try searching it up, if not let me know and i can go check for you

Use TweenService

wow i totally didnt know that.

is that sarcasm…?
I would certainly hope not lol

yes it is lol, i know how to tween, but the exact code im not sure

hey are you a good programmer? if so could you maybe check out my post i have a problem with loading a table from datastore, it would be greatly appreciated :slight_smile:

Use private messages for this.

Here you go.

local function tweenMaterial(part, material, duration, style, direction)
	if style == nil then
		style = Enum.EasingStyle.Quad
	end
	
	if direction == nil then
		direction = Enum.EasingDirection.Out
	end
	
	local part2 = part:Clone()
	part2:ClearAllChildren()
	part2.Transparency = 1
	part2.CanCollide = false
	part2.Material = material
	
	local weld = Instance.new('WeldConstraint', part2)
	weld.Part0 = part2
	weld.Part1 = part
	part2.Parent = workspace
	
	local tweenService = game:GetService('TweenService')
	local tweenInfo = TweenInfo.new(duration, style, direction)
	local tween1 = tweenService:Create(part, tweenInfo, {Transparency = 1})
	local tween2 = tweenService:Create(part2, tweenInfo, {Transparency = part.Transparency})
	
	tween1:Play()
	tween2:Play()
	
	tween2.Completed:Connect(function()
		tween1.Completed:Wait()
		part.Material = material
		part.Transparency = part2.Transparency
		part2:Destroy()
	end)
end

Use it like this:

tweenMaterial(workspace.TweenPart, Enum.Material.Grass, 1)

Tweens workspace.TweenPart from whatever material it is currently, to grass, over a duration of 1 second. Works with constraint systems and ObjectValues referring to it in random places and literally every single thing conceivable in Roblox, pretty much. As long as nothing triggers on descendant/child add to workspace. The material of the part changes at the end of the visual effect.

You can specify easing style and direction with extra arguments to the function like TweenInfo.new.

1 Like

Just gonna add a little bit to Terrodactyl

local part = game.Workspace.Part

local tweenServ = game:GetService( "TweenService")
 
local tweenInf = tweenInfo.new(
--[ Time the tween should take ]--  0.5,
--[ Style of how it tweens]-- Enum.EasingStyle.Linear,
--[Way it tweens]-- Enum.EasingDirection.Out, 
--[How many times the tween will repeat]-- 5,
--[Whether the tween will reverse after it finishes]-- false,
--[How long the delay between each repetition will be]-- 0.5
)

--Create the tween
local change = tweenServ:Create( --[The part you want to tween]-- part, --[The tweenInfo you want the tween to use]-- tweenInf, --[the property(s) you want the tween to change. Remember to put it in {} ]-- { Position = Vector3.new(5,5,5)      Size = Vector3.new(8,10,8 } )

--Play the tween
change:Play()

In the tween, you can change the Linear in
Enum.EasingStyle.Linear to whichever style you want, like Bounce and Sine. Right when you type in Enum.EasingStyle. , a bunch of options should pop up.

Enum.EasingDirection.In is the same thing. The 3 options are In. , Out. , and inOut. I don’t really know what the difference between those 3 are, but nevermind.

Your code is so confusing and spaced out and uses unnecessary arguments…

Just refer to the documentation for TweenService. its method :Create() takes a TweenInfo

Your one didn’t really explain how to make the tween, but whatever.

Oh, sorry. You can see all that in its own little section, where all the locals begin with tween. Hopefully the docs help with that too, if OP/anyone needs more info on it.

Also, I didn’t mean to be rude if my last post came off that way.

1 Like

this was so helpful thank you so much!