Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to prevent "Unable to cast to Dictionary" error with tween?

I am currently trying to make a script to move a part to where the mouse is pointing, when I run the script it returns an error saying "Unable to cast to Dictionary" and I have no clue how to fix this.

game.ReplicatedStorage.Events.SpellFired.OnServerEvent:Connect(function(plr,spell,pos)
	local SpellPart = game.ReplicatedStorage.Spells.FireBall
	local copy = SpellPart:Clone()
	local TweenService = game:GetService("TweenService")
	local tweenInfo = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.In,1,false,0)
	copy.Parent = workspace
	game.Workspace.FireBall.Position = workspace[plr.Name].HumanoidRootPart.Position
	local tween = TweenService:Create(copy, tweenInfo, pos)
	wait(6)
	copy:Destroy()
end)

The "pos" variable is a Vector3

1 answer

✓ Accepted answer

Let's look at the TweenService:Create() arguments. The developer wiki states: (instance,tweenInfo,propertyTable). Now let's look at your arguments: (copy, tweenInfo, pos). Copy is an Instance, tweenInfo is a tweenInfo, however, pos is a Vector3, not a table. Here's how it'd look like: {Position = Vector3.new(0,0,0)}. So let's implement that into your script:

game.ReplicatedStorage.Events.SpellFired.OnServerEvent:Connect(function(plr,spell,pos)
    local SpellPart = game.ReplicatedStorage.Spells.FireBall
    local copy = SpellPart:Clone()
    local TweenService = game:GetService("TweenService")
    local tweenInfo = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.In,1,false,0)
    copy.Parent = workspace
    game.Workspace.FireBall.Position = workspace[plr.Name].HumanoidRootPart.Position
    local tween = TweenService:Create(copy, tweenInfo, {Position = pos}) -- it has to be the exact name of the property, and then you wanna set the value
    tween:Play() -- dunno if you missed this line by accident, but im just putting it here
    wait(6)
    copy:Destroy()
end)

Hope this helped!

1 comment

0

Thank you so much!

This discussion is preserved as it was. New answers, comments, and votes are closed.