Unable to cast string to token (Error)

Hi, I’m making Hunger Icon with youtube tutorial, I have problem with script.

[Youtube Link]

Heres my script and error.

local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild('Humanoid')

local hunger = player.Info.Hunger

while wait(1) do
	if humanoid.Health > 0 then
		if hunger.Value > 0 then
			hunger.Value = hunger.Value - 1
		else
			humanoid:TakeDamage(10)
		end
		
		local fullHunger = 1
		local currHunger = hunger.Value / 100
		clip:TweenSize(UDim2.new(1, 0, -currHunger, 0), 'InQut', 'Sine', 1)
	else
		print('test')
	end
end```

Error

Unable to cast string to token  -  Client - LocalScript:18

What value is hunger? Is that a string value?
If so, change that to a numberValue or intValue.

Is this the line that the error is coming from?

1 Like

It’s IntValue, I will show you screenshot.

1 Like

Yeah, It is coming from. that line.

game.Players.PlayerAdded:Connect(function(player)
local Info = Instance.new(‘Folder’, player)
local Hunger = Instance.new(‘IntValue’, Info)
Info.Name = ‘Info’
Hunger.Name = ‘Hunger’
Hunger.Value = 100
end)

Alright.

One note about this script:
Do not put the parent as a paremeter, it affects performance.

I’ll now check the issue.

1 Like

Okay, I will be wait, Thanks for helping me.

Try this:


local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild('Humanoid')

local hunger = player:WaitForChild("Info").Hunger

while task.wait(1) do
	if humanoid.Health > 0 then
		if hunger.Value > 0 then
			hunger.Value = hunger.Value - 1
		else
			humanoid:TakeDamage(10)
		end
		
		local fullHunger = 1
		local currHunger = hunger.Value / 100
        print(hunger.Value)
		clip:TweenSize(UDim2.new(1, 0, -currHunger, 0), 'InQut', 'Sine', 1)
	else
		print('test')
	end
end

Need I add clip local? You didn’t added Clip local.

image

What is clip ? I dont see it in the original post

Maybe, My mistake I will add it.

I’m still getting error of Unable to cast string to token - Client - LocalScript:19

That Line, clip:TweenSize(UDim2.new(1, 0, -currHunger, 0), ‘InQut’, ‘Sine’, 1)

  1. Show us what clip is.
  2. Do the prints get out?

local clip = script.Parent
image

local clip = script.Parent
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild(‘Humanoid’)

local hunger = player:WaitForChild(“Info”).Hunger

while task.wait(1) do
if humanoid.Health > 0 then
if hunger.Value > 0 then
hunger.Value = hunger.Value - 1
else
humanoid:TakeDamage(10)
end

	local fullHunger = 1
	local currHunger = hunger.Value / 100
	print(hunger.Value)
	clip:TweenSize(UDim2.new(1, 0, -currHunger, 0), 'InQut', 'Sine', 1)
else
	print('test')
end

end

The middle 2 paramaters should be enums:

clip:TweenSize(UDim2.new(1, 0, -currHunger, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 1)
1 Like

Oh, It works but something wrong