Changing terrain material color with tween service?

so im new to tween service and i made a script which should change rock terrain material color but its not working.

local function changerockcolor()
	local rockcolor = Color3.fromRGB(106,127,63)
	local currentcolor = game.Workspace.Terrain:GetMaterialColor(Enum.Material.Rock)
	game.Workspace.Colors.Rock.Value = currentcolor
	if game.Workspace.Terrain:GetMaterialColor(Enum.Material.Rock) ~= rockcolor then
		game:GetService("TweenService"):Create(game.Workspace.Colors.Rock.Value,TweenInfo.new(.5),{rockcolor}):Play()
		game.Workspace.Terrain:SetMaterialColor(Enum.Material.Rock,game.Workspace.Colors.Rock.Value)
	end
end

error i am getting: Unable to cast to Dictionary

1 Like

You need to set a key inside the table given to :Create() for the property name. :Create() takes an object, not a value, as its first argument.

okay i think i understand what youre saying

Yeh. TweenService:Create() take’s a instance for its first parameter. So you would simply get rid of Value. I would do tween the color by using a Color3 value.

local terrain = game.Workspace.Terrain
local tweenService = game:GetService("TweenService")

local function changerockcolor()  
local rockcolor = Color3.fromRGB(106,127,63)  
local colorValue = game.Workspace.colorValue 

colorValue.Value = terrain:GetMaterialColor("Rock")
   colorValue:GetPropertyChangedSignal("Value"):Connect(function()
   terrain:SetMaterialColor("Rock", colorValue.Value)
end)

local tweenInfo = TweenInfo.new(.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0)
    if game.Workspace.Terrain:GetMaterialColor("Rock") ~= rockcolor then
    local tween = tweenService:Create(colorValue, tweenInfo, {Value = rockcolor}) 
    tween:Play()

   end
end
1 Like