Unable to cast value to object: Tween

Hello! I was scripting a custom error message to appear with a tween, but it gives me an error: Unable to cast value to object

This is the line that has the error

local Tween1 = TweenService:Create(plrgui.tool.Text,TweenInfo1,{TextTransparency = 0})

Here is the full script for context

local PriceModule = require(game.ReplicatedStorage.Modules.ItemPrices)
local TweenService = game:GetService("TweenService")

script.Parent.ProximityPrompt.TriggerEnded:Connect(function(player)
	local Item = player.Character:FindFirstChildWhichIsA("Tool") or player.Backpack:FindFirstChildWhichIsA("Tool")
	local plrgui = player.PlayerGui:WaitForChild("PlayerInterface")
	if Item then
		if Item == player.Character:FindFirstChildWhichIsA("Tool") then
			plrgui.tool.TextTransparency = 1
		end
		local Money = game.ReplicatedStorage.Values.Money
		Money.Value = Money.Value + PriceModule[Item.Name]
		print("sold for "..PriceModule[Item.Name])
		Item:Destroy()
		plrgui.Money.Text = "money: "..Money.Value
	else 
		plrgui.tool.Text = "You don't have anything to sell"
		plrgui.tool.TextColor3 = Color3.new(1, 0.25098, 0.25098)
		local TweenInfo1 = TweenInfo.new(0.5,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut,0,false,0)
		local Tween1 = TweenService:Create(plrgui.tool.Text,TweenInfo1,{TextTransparency = 0})
		Tween1:Play()
		wait(5.5)
		local Tween2 = TweenService:Create(plrgui.tool.Text,TweenInfo1,{TextTransparency = 1})
		Tween2:Play()
		plrgui.tool.TextColor3 = Color3.new(1,1,1)
	end
end)

Thank you so much for reading and have a nice day.

That error normally means that you have put a property as your first argument and if you look at the tween it seems you have. So to fix it we just have to change your line to this:

local Tween1 = TweenService:Create(plrgui.tool,TweenInfo1,{TextTransparency = 0})

All I did was just change the plrgui.tool.Text to plrgui.tool. You also have to do this for your Tween2 variable

1 Like

It now doesn’t give an error, but it doesn’t show the text either

Wait can I see a screenshot of your explorer please. I think I might know the problem, do you have an object called “Text” in the explorer which is a child of the tool or something.

Here is the GUI, the tween should modify the transparency on the “tool” textlabel
image
The script is not in the ui nor in the tool, just using a textlabel both for tools and this

Are you sure the text object hasn’t got the property Visible set to false.

1 Like

Yes, sorry. I forgot that I had by default the text hidden. I just have to make it visible when the tween plays. Thank you