Unable to cast to Dictionary with Tweens

I want to create a button that when clicked uses a tween to grow/scale up a player (make them big). I am getting the following error:

Error

Here is my code. It is not the cleanest, so bonus points if you can teach me how to index a dictionary of tweens.

My Code
local detector = script.Parent

detector.MouseClick:Connect(function(plr)
	print(plr.Name .." has clicked the button!")

	local char = plr.Character.Humanoid

	local tweenService = game:GetService("TweenService")
		
	local tweenInfo = TweenInfo.new(
		10, -- Time
		Enum.EasingStyle.Exponential, -- Easing Style (Linear, X, and X)
		Enum.EasingDirection.Out,
		0, -- Repeat count (set to -1 to repeat forever)
		false, -- Reverse (true/false)
		0 -- Delay time	
	)
		
	local values = {
		height = (char.BodyHeightScale.Value * 2),
		depth = (char.BodyDepthScale.Value * 2),
		width = (char.BodyWidthScale.Value * 2),
		head = (char.HeadScale.Value * 2)
	}

	local tweens = {
		heightTween = tweenService:Create(char.BodyHeightScale.Value, tweenInfo, values.height),
		depthTween = tweenService:Create(char.BodyDepthScale.Value, tweenInfo, values.depth),
		widthTween = tweenService:Create(char.BodyWidthScale.Value, tweenInfo, values.width),
		headTween = tweenService:Create(char.HeadScale.Value, tweenInfo, values.head)
	}	
		
	tweens.heightTween:Play()
	tweens.depthTween:Play()
	tweens.widthTween:Play()
	tweens.headTween:Play()
end)

  1. If the values for the last three arguments of TweenInfo are as follows: 0, false, 0, then you can remove them because it will automatically default to it.
  2. The third argument of TweenService:Create() accepts a table with names of properties with what you want to change it into, such as {Property = 14}, not (char.Property = 14). (you’re also using the wrong brackets).
  3. Instead of playing the tweens from the table one by one, you can loop through them using a for loop.
local detector = script.Parent

detector.MouseClick:Connect(function(plr)
	print(plr.Name .." has clicked the button!")

	local char = plr.Character.Humanoid

	local tweenService = game:GetService("TweenService")
		
	local tweenInfo = TweenInfo.new(
		10, -- Time
		Enum.EasingStyle.Exponential, -- Easing Style (Linear, X, and X)
		Enum.EasingDirection.Out,
		0, -- Repeat count (set to -1 to repeat forever)
		false, -- Reverse (true/false)
		0 -- Delay time	
	)
		
	local values = {
		height = {Value = char.BodyHeightScale.Value * 2},
		depth = {Value = char.BodyDepthScale.Value * 2},
		width = {Value = char.BodyWidthScale.Value * 2},
		head = {Value = char.HeadScale.Value * 2}
	}

	local tweens = {
		heightTween = tweenService:Create(char.BodyHeightScale, tweenInfo, values.height),
		depthTween = tweenService:Create(char.BodyDepthScale, tweenInfo, values.depth),
		widthTween = tweenService:Create(char.BodyWidthScale, tweenInfo, values.width),
		headTween = tweenService:Create(char.HeadScale, tweenInfo, values.head)
	}	
		
	for _, tween in pairs(tweens) do
		tween:Play()
	end
end)

Your values table isn’t setup properly. The :Create() expects you to define the property and value, not just the value. Try using the below script and see if it works.

local detector = script.Parent

detector.MouseClick:Connect(function(plr)
	print(plr.Name .." has clicked the button!")

	local char = plr.Character.Humanoid

	local tweenService = game:GetService("TweenService")
		
	local tweenInfo = TweenInfo.new(
		10, -- Time
		Enum.EasingStyle.Exponential, -- Easing Style (Linear, X, and X)
		Enum.EasingDirection.Out,
		0, -- Repeat count (set to -1 to repeat forever)
		false, -- Reverse (true/false)
		0 -- Delay time	
	)
		
	local values = {
		BodyHeightScale = (char.BodyHeightScale.Value * 2),
		BodyDepthScale = (char.BodyDepthScale.Value * 2),
		BodyWidthScale = (char.BodyWidthScale.Value * 2),
		HeadScale = (char.HeadScale.Value * 2)
	}

	local tweens = {
		heightTween = tweenService:Create(char, tweenInfo, values),
		depthTween = tweenService:Create(char, tweenInfo, values),
		widthTween = tweenService:Create(char, tweenInfo, values),
		headTween = tweenService:Create(char, tweenInfo, values)
	}	
		
	tweens.heightTween:Play()
	tweens.depthTween:Play()
	tweens.widthTween:Play()
	tweens.headTween:Play()
end)

Thanks! It ended up being:

xTween = tweenService:Create(char.xScale, tweenInfo, values.x)

etc.

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