Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Unable to cast dictionary problem how i fix?

Asked by 2 years ago
Edited 2 years ago

So i was making an obby and i wanted to do a moving part with tween service i did it and then it said "unable to cast dictionary"

wait(1) twee = game:GetService("TweenService") local part = script.Parent

local info = TweenInfo.new( 5, Enum.EasingStyle.Elastic, Enum.EasingDirection.Out, -1, true, 0 )

local create = { part.Position == Vector3.new(-194.115, 34.227, -1.536) }

local tweencreate = twee:Create(part,info,create)

tweencreate:Play()

0
the last line the play thing i separate it so it isnt the error ferr56754n 5 — 2y

1 answer

Log in to vote
1
Answered by 2 years ago

Happy St. Patrick's Day!

I have a solution for you!

Inside the 'Create' table, you did part.Position, instead of part.Position, just do Position, and replace == with =.

e.g:

local create = { Position = Vector3.new(-194.115, 34.227, -1.536) }

I have decided to expand upon your script. I have a new-and-improved version!

local reachedGoal = false
local OGPos = script.Parent.Position
local GoalPos = workspace.Part2.Position -- Replace Part2 with the name of your part.
local Tween = game:GetService("TweenService")
local part = script.Parent
local infotime = 5
local info = TweenInfo.new( infotime, Enum.EasingStyle.Elastic, Enum.EasingDirection.Out, 0, true, 0 )

while wait(1) do
    if reachedGoal == false then

        local info = TweenInfo.new( 5, Enum.EasingStyle.Elastic, Enum.EasingDirection.Out, 0, true, 0 )


        local tweencreate = Tween:Create(part,info,{Position = GoalPos})

        tweencreate:Play()

        tweencreate.Completed:Connect(function()
            reachedGoal = true
            print("Reached Second Position.")
        end)
        wait(infotime + 2.5)

    else

        local tweencreate = Tween:Create(part,info,{Position = OGPos})

        tweencreate:Play()

        tweencreate.Completed:Connect(function()
            reachedGoal = false
            print("Reached First Position.")
        end)

        wait(infotime + 2.5)

    end
end

LOTS to explain here, so time to begin.

I added a variable called 'reachedGoal' which is used later on. I added 2 position variables, our original position and our Part2 position. Then some extra variables, then a loop. This loop checks if reachedGoal is either true or false every second. If reachedGoal is false, then we continue. We get the info, then create the tween. It gets the part, info, and the Position. Since reachedGoal is false, we go to GoalPos (aka Part2's position). We paly the animation, and start a Completed function. The Completed function fires when the Tween is, well, completed! It switches reachedGoal to true, and then it fires the opposite code. It's basically the same code, just with some differences. Instead of GoalPos, it's OGPos.

Also, after both these functions, theres a wait(). This makes it wait the amount of time the tween is with the added 2.5 wait.

That's basically it, thanks for reading, and if you found this helpful, make sure you set this as 'solved'!

0
I agree with the other answer, but also any time you put code in make sure to put it in a code block and specidy which line the error is on. Verse_NOVA 52 — 2y
0
I like that you have explained your code but just a recommendation to help get your point across. Seperate all your changes and explain them with examples, then combine it all at the end. It makes it much more clear. Benbebop 1049 — 2y
0
Thanks for the info Benbebop, I'll use that next time! LikeableEmmec 470 — 2y
Ad

Answer this question