Unable to cast value to function

im trying to make all guis tween away when the player clicks play but when I tried to use Udim2 the output said its “Unable to cast value to function” this is my code:

script.Parent.MouseButton1Click:Connect(function()
	
	hrp.Anchored = false
	
	settingsbutton:TweenPosition(UDim2.new(-1, 0, 0.644, 0), "InOut", "Sine", 0.5, true, false)
	task.wait(0.2)
	creditsbutton:TweenPosition(UDim2.new(2, 0, 0.644, 0), "InOut", "Sine", 0.5, true, false)
	task.wait(0.2)
	title:TweenPosition(UDim2.new(0.188, 0, -2, 0), "InOut", "Sine", 0.5, true, false)
	task.wait(0.2)
	playbutton:TweenPosition(UDim2.new(0.398, 0, -1, 0),"InOut", "Sine", 0.5, true, false)
	task.wait(0.2)
	Background:TweenPosition(UDim2.new(0, 0, 1, 0),"InOut", "Sine", 0.5, true, false)
	settingsbutton.Visible = false
	settingsbutton.Active = false
	creditsbutton.Visible = false
	creditsbutton.Active = false
	title.Visible = false
	title.Active = false
	playbutton.Visible = false
	playbutton.Active = false
	Background.Visible = false
	Background.Active = false
	
end)


you’re supposed to use the enums describing the easing style and direction, not the names themselves.

Enum.EasingDirection.InOut
Enum.EasingStyle.Sine

You can use names, thought its depricated and outdated, the code should still work

“Deprecated” and “still work” does not fit in the same sentence lol, if it’s deprecated then its bound to break in the future (which can be now)

But yeah after checking again this is probably the issue


The last parameter is a function and the OP is giving it a boolean instead

This kind of worked but now only one of the guis mentioned in the code is tweening

after the commas, press enter to make a new line and look where the line is gonna say the error

1 Like

You made the override function false instead of just leaving it blank (or nil but im not sure), this should fix it.

script.Parent.MouseButton1Click:Connect(function()
	
	hrp.Anchored = false
	
	settingsbutton:TweenPosition(UDim2.new(-1, 0, 0.644, 0), "InOut", "Sine", 0.5, true)
	task.wait(0.2)
	creditsbutton:TweenPosition(UDim2.new(2, 0, 0.644, 0), "InOut", "Sine", 0.5, true)
	task.wait(0.2)
	title:TweenPosition(UDim2.new(0.188, 0, -2, 0), "InOut", "Sine", 0.5, true)
	task.wait(0.2)
	playbutton:TweenPosition(UDim2.new(0.398, 0, -1, 0),"InOut", "Sine", 0.5, true)
	task.wait(0.2)
	Background:TweenPosition(UDim2.new(0, 0, 1, 0),"InOut", "Sine", 0.5, true)
	settingsbutton.Visible = false
	settingsbutton.Active = false
	creditsbutton.Visible = false
	creditsbutton.Active = false
	title.Visible = false
	title.Active = false
	playbutton.Visible = false
	playbutton.Active = false
	Background.Visible = false
	Background.Active = false
	
end)

what do you mean by this? The output doesn’t detect any errors

Alr so what I did wrong wasn’t in the script shown. When i was listing the variables i accidentally didn’t reference the playergui and instead referenced the starter gui and therefore it did not work
What i did wrong:

local settingsbutton = game.StarterGui.PlayScreen.ImageLabel.Frame.Buttons.Settings
local creditsbutton = game.StarterGui.PlayScreen.ImageLabel.Frame.Buttons.Settings
local playbutton = script.Parent
local title = game.StarterGui.PlayScreen.ImageLabel.Frame.Title
local Background = game.StarterGui.PlayScreen.ImageLabel
local hrp = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")


Finished code:

local settingsbutton = script.Parent.Parent.Settings
local creditsbutton = script.Parent.Parent.Credits
local playbutton = script.Parent
local title = script.Parent.Parent.Parent.Title
local Background = game.StarterGui.PlayScreen.ImageLabel
local hrp = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.