Attempt to call a instance value

I got two scripts, both with the same code and such, and yet one of them doesn’t work. It’s a tween function I’m trying to do. Here’s the main code:

local function Tween(Object,Value)
	local OutTween = ts:Create(Object,inf,{ImageTransparency = Value})
	OutTween:Play()
end

Tween(obj,value) --- this is just an example but you get the picture

Then here are the two scripts:
NOT WORKING

local ts = game:GetService('TweenService')
local button = script.Parent.leaveButton
local tweeninf = TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false, 0)

local function Tween(Object,Value)
	local OutTween = ts:Create(Object,tweeninf,{ImageTransparency = Value})
	OutTween:Play()
end

button.MouseEnter:Connect(function()
	script.Parent.Static:Play()
	local Tween = ts:Create(script.Parent.Static, TweenInfo.new(1, Enum.EasingStyle.Linear), {Volume = 1})
	Tween:Play()
	Tween(button.ImageLabel,0)
end)

button.MouseEnter:Connect(function()
	local Tween = ts:Create(script.Parent.Static, TweenInfo.new(1, Enum.EasingStyle.Linear), {Volume = 0})
	Tween:Play()
	Tween.Completed:Wait()
	script.Parent.Static:Stop()
	Tween(button.ImageLabel,1)
end)

WORKING

local ts = game:GetService("TweenService")
local inf = TweenInfo.new(0.5,Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, false, 0)

local function Tween(Object,Value)
	local OutTween = ts:Create(Object,inf,{ImageTransparency = Value})
	OutTween:Play()
end

local part = game.Workspace.improvedtext
local canhit = true

local chapter = script.Parent.chapter
local info = script.Parent.info

chapter.AnchorPoint = Vector2.new(0, 0)
chapter.Position = UDim2.new(0.277, 0, 0.236, 0)

info.AnchorPoint = Vector2.new(0, 0)
info.Position = UDim2.new(0.356, 0, 0.362, 00)

game.ReplicatedStorage.Touch.OnClientEvent:Connect(function()
	if canhit == true then
		canhit = false
		script.Parent.Visible = true
		Tween(script.Parent.chapter,0)
		chapter:TweenPosition(UDim2.new(0.277, 0,0.166, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quad)
		wait(0.25)
		Tween(script.Parent.info,0)
		info:TweenPosition(UDim2.new(0.356, 0,0.296, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quad)
		wait(4)
		Tween(script.Parent.chapter,1)
		chapter:TweenPosition(UDim2.new(0.277, 0, 0.236, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quad)
		Tween(script.Parent.info,1)
		info:TweenPosition(UDim2.new(0.356, 0, 0.362, 00), Enum.EasingDirection.Out, Enum.EasingStyle.Quad)
	canhit = true
	end
end)

It errors both at line 14 and line 22 (NOT WORKING) code.

I don’t know why it’s like that, if anyone can help me that would be greatly appreciated, ty!

Your working code sports a function named Tween. Your faulty code on the other hand, uses a Tween object, not a function.

how would i go with it? since its the same thing?

Oh, I just noticed you also have the Tween function in the faulty code.

If you set a new value under the same variable name (even function names count), you override the old value with the new value:

local Value = 2

print(Value) -- 2

local Value = 20

print(Value) -- 20

If you did this in a separate scope (function, if, do, for do, etc.) the old value will not be changed (unless you do not use local, in which it will be overridden).

local a = 2
print(a) -- 2

do
	local a = 20
	print(a) -- 20
end
print(a) -- still 2.

In your case, you made a Tween function, yet here:

You overrode the function. Simply using a different name will work.

This is evident in both button.MouseEnter connections.

1 Like

I’ve changed both things but it didn’t work somehow.

local ts = game:GetService('TweenService')
local button = script.Parent.leaveButton
local tweeninf = TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false, 0)

local function Tween(Object,Value)
	local OutTween = ts:Create(Object,tweeninf,{ImageTransparency = Value})
	OutTween:Play()
end

button.MouseEnter:Connect(function()
	script.Parent.Static:Play()
	local TweenObj = ts:Create(script.Parent.Static, TweenInfo.new(1, Enum.EasingStyle.Quart), {Volume = 1})
	TweenObj:Play()
	Tween(button.ImageLabel,0)
end)

button.MouseEnter:Connect(function()
	local TweenObj2 = ts:Create(script.Parent.Static, TweenInfo.new(1, Enum.EasingStyle.Quart), {Volume = 0})
	TweenObj2:Play()
	TweenObj2.Completed:Wait()
	script.Parent.Static:Stop()
	Tween(button.ImageLabel,1)
end)

What’s weird is if I change the line 20 to say Tween.Completed:Wait(), it works, but when its in that script, it just doesn’t work. There’s no errors, or anything

nvm. that was on my part. I shouldn’t have used the Completed event. Just changed it to the TweenInfo num. Thank you though!

1 Like