Unable to cast to dictionary error

It gives a Unable to cast to dictionary error on the 8th line

local Emerald = script.Parent

local text = game.StarterGui.GemFounded:WaitForChild('GemFoundedText')

local GameStarted = script.Parent:FindFirstChild('GameStarted')
local TS = game:GetService('TweenService')
local TI = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, false, 0)
local textTween = TS:Create(text, TI, {Position = 0.5, 0, 0.091, 0});

Emerald.Touched:Once(function(hit)
	if hit.Parent:FindFirstChild('Humanoid') and GameStarted.Value == true and text.Position == CFrame.new(0.5, 0, -0.051, 0) then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player then
			local username = player.Name
			
			text.Text = 'Emerald has been found by'.. username .. '!'
			textTween:Play()
			
		else
			
			warn('Bişey yanlış gitti')

		end
	end
end)
5 Likes

The issue is that the position in 3D space must be Vector3

Here is corrected script:

local Emerald = script.Parent

local text = game.StarterGui.GemFounded:WaitForChild('GemFoundedText')

local GameStarted = script.Parent:FindFirstChild('GameStarted')
local TS = game:GetService('TweenService')
local TI = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, false, 0)
local textTween = TS:Create(text, TI, {Position = Vector3.new(0.5, 0, 0.091, 0)}); -- Position in 3D space must be Vector3

Emerald.Touched:Once(function(hit)
	if hit.Parent:FindFirstChild('Humanoid') and GameStarted.Value == true and text.Position == CFrame.new(0.5, 0, -0.051, 0) then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player then
			local username = player.Name

			text.Text = 'Emerald has been found by'.. username .. '!'
			textTween:Play()

		else

			warn('Bişey yanlış gitti')

		end
	end
end)
4 Likes

it gives this error

TweenService:Create property named 'Position' cannot be tweened due to type mismatch (property is a 'UDim2', but given type is 'Vector3')  -  Server - TextSystem:8
1 Like

My critical mistake and I apologize for it!

Try this instead:

local Emerald = script.Parent

local text = game.StarterGui.GemFounded:WaitForChild('GemFoundedText')

local GameStarted = script.Parent:FindFirstChild('GameStarted')
local TS = game:GetService('TweenService')
local TI = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, false, 0)
local textTween = TS:Create(text, TI, {Position = UDim2.new(0.5, 0, 0.091, 0)}); -- 2d space :)

Emerald.Touched:Once(function(hit)
	if hit.Parent:FindFirstChild('Humanoid') and GameStarted.Value == true and text.Position == CFrame.new(0.5, 0, -0.051, 0) then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player then
			local username = player.Name

			text.Text = 'Emerald has been found by'.. username .. '!'
			textTween:Play()

		else

			warn('Bişey yanlış gitti')

		end
	end
end)
3 Likes

It worked but now it gives this error lol

Workspace.Part.TextSystem:11: attempt to index nil with 'Value'  -  Server - TextSystem:11
2 Likes

Can you check if 'GameStartered" is on its proper location.

If it is, I would really appreciate if you send a picture of workspace where the system is located, in order for us to help you :slight_smile:

2 Likes

Oh thank you i found the problem the GameStarted value is not in script.Parent let me try to fix it and try again

2 Likes

Just founded another issue where text label position is set to CFrame

Here is corrected script

local Emerald = script.Parent

local text = game.StarterGui.GemFounded:WaitForChild('GemFoundedText')

local GameStarted = script.Parent:FindFirstChild('GameStarted')
local TS = game:GetService('TweenService')
local TI = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, false, 0)
local textTween = TS:Create(text, TI, {Position = UDim2.new(0.5, 0, 0.091, 0)}); -- 2d space :)

Emerald.Touched:Once(function(hit)
	if hit.Parent:FindFirstChild('Humanoid') and GameStarted.Value == true and text.Position == UDim2.new(0.5, 0, -0.051, 0) then -- CFrame -> Udim2 
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player then
			local username = player.Name

			text.Text = 'Emerald has been found by'.. username .. '!'
			textTween:Play()

		else

			warn('Bişey yanlış gitti')

		end
	end
end)
3 Likes

Hello,
I just wanted to inform you that tweens don’t work for text like that
In order to tween a GUI ASSET you need to -

Gui:TweenPosition(...) -- changes position
Gui:TweenSize(...) -- changes size
Gui:TweenSizeAndPosition(...) -- changes both size and position

-- specify parameters accordingly

By the way, I am new to the DevFourm.

2 Likes

tweens do work like that, all of the functions you’ve just mentioned are deprecated in favor of tweenservice.

Your way is not good practice. Use tweenservice for UI.

3 Likes

Nope its not right. It is not decaperated and If i am wrong about this show me how to do it please.
and I find the only way to tween the UI’s Size and Position is this

In a big red box on the documentation page for the functions you mentioned, it clearly says it is deprecated.

To tween the position/size of a UI, do:

local UI = ...
local TIME = 1

TweenService:Create(UI, TweenInfo.new(TIME), {Position = UDim2.new(), Size=UDim2.new()}):Play()

very very barebones example, but it shows the main idea

1 Like

yes it is bro, you can’t just dismiss something without fact checking, as @SeargentAUS already said, there is a big red box, with nice letters stating: “Deprecated”.

edit: I realised my response might come off as offensive, I am sorry if this offends you.

I must had been outdated.
I usually don’t check weather these types of things are deprecated. Sorry

1 Like

No issues it wasn’t offensive.
I was just quite outdated on this topic of TweenService.
During the time I learned it about this, we couldn’t use TweenService to tween the position at those times. I remember struggling to find out that it wouldn’t work.

1 Like

The only reason I see to this for a dictionary error is the {Position = 0.5, 0, 0.091, 0}
The solution to this is -

local Emerald = script.Parent

local text = game.StarterGui.GemFounded:WaitForChild('GemFoundedText')

local GameStarted = script.Parent:FindFirstChild('GameStarted')
local TS = game:GetService('TweenService')
local TI = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, false, 0)
local textTween = TS:Create(text, TI, {Position = UDim2.new(0.5, 0, 0.091, 0)});

Emerald.Touched:Once(function(hit)
	if hit.Parent:FindFirstChild('Humanoid') and GameStarted.Value == true and text.Position == CFrame.new(0.5, 0, -0.051, 0) then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player then
			local username = player.Name
			
			text.Text = 'Emerald has been found by'.. username .. '!'
			textTween:Play()
			
		else
			
			warn('Bişey yanlış gitti')

		end
	end
end)