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

why unable to cast to object error?

Asked by 2 years ago
while wait() do
    b = game.ReplicatedStorage.gun:Clone()
    b.Parent = workspace
    h = b.Position
    tween = game:GetService("TweenService")
    tween:Create(h, TweenInfo.new(((workspace.goal1.Position.x - h.X)/2+(workspace.goal1.Position.Z - h.Z)/2)/2), {Position = workspace.goal1.Position}):Play()
    wait(((workspace.goal1.Position.x - h.X)/2+(workspace.goal1.Position.Z - h.Z)/2)/2)


    tween:Create(h, TweenInfo.new(((workspace.goal1.Position.x - h.X)/2+(workspace.goal2.Position.Z - h.Z)/2)/2), {Position = workspace.goal2.Position}):Play()
    wait(((workspace.goal2.Position.x - h.X)/2+(workspace.goal2.Position.Z - h.Z)/2)/2)


    tween:Create(h, TweenInfo.new(((workspace.goal3.Position.x - h.X)/2+(workspace.goal3.Position.Z - h.Z)/2)/2), {Position = workspace.goal3.Position}):Play()
    wait(((workspace.goal3.Position.x - h.X)/2+(workspace.goal3.Position.Z - h.Z)/2)/2)


    tween:Create(h, TweenInfo.new(((workspace.goal4.Position.x - h.X)/2+(workspace.goal4.Position.Z - h.Z)/2)/2), {Position = workspace.goal4.Position}):Play()
    wait(((workspace.goal4.Position.x - h.X)/2+(workspace.goal4.Position.Z - h.Z)/2)/2)


    tween:Create(h, TweenInfo.new(((workspace.goal5.Position.x - h.X)/2+(workspace.goal5.Position.Z - h.Z)/2)/2), {Position = workspace.goal5.Position}):Play()
    wait(((workspace.goal5.Position.x - h.X)/2+(workspace.goal5.Position.Z - h.Z)/2)/2)


    tween:Create(h, TweenInfo.new(((workspace.goal6.Position.x - h.X)/2+(workspace.goal6.Position.Z - h.Z)/2)/2), {Position = workspace.goal6.Position}):Play()
    wait(((workspace.goal6.Position.x - h.X)/2+(workspace.goal6.Position.Z - h.Z)/2)/2)


    tween:Create(h, TweenInfo.new(((workspace.goal7.Position.x - h.X)/2+(workspace.goal7.Position.Z - h.Z)/2)/2), {Position = workspace.goal7.Position}):Play()
    wait(((workspace.goal7.Position.x - h.X)/2+(workspace.goal7.Position.Z - h.Z)/2)/2)


    tween:Create(h, TweenInfo.new(((workspace.goal8.Position.x - h.X)/2+(workspace.goal8.Position.Z - h.Z)/2)/2), {Position = workspace.goal8.Position}):Play()
    wait(((workspace.goal8.Position.x - h.X)/2+(workspace.goal8.Position.Z - h.Z)/2)/2)


    tween:Create(h, TweenInfo.new(((workspace.goal9.Position.x - h.X)/2+(workspace.goal9.Position.Z - h.Z)/2)/2), {Position = workspace.goal9.Position}):Play()
    wait(((workspace.goal9.Position.x - h.X)/2+(workspace.goal9.Position.Z - h.Z)/2)/2)


    tween:Create(h, TweenInfo.new(((workspace.goal10.Position.x - h.X)/2+(workspace.goal10.Position.Z - h.Z)/2)/2), {Position = workspace.goal10.Position}):Play()
    wait(((workspace.goal10.Position.x - h.X)/2+(workspace.goal10.Position.Z - h.Z)/2)/2)
end

I'm trying to make the gun move places in the factory. the gun is a union operation and not a model. the error is on every tween created. how fix?

1 answer

Log in to vote
1
Answered by 2 years ago

The reason your tween is not working is because the parameters you entered are wrong. There parameters of the tween are explained in the code.

The first parameter you enter is a Position rather than the part you want to tween.

Here is an example. I would recommend you read more about TweenService here. https://developer.roblox.com/en-us/api-reference/class/TweenService

b = game.ReplicatedStorage.gun:Clone()
b.Parent = workspace
h = b.Position
tween = game:GetService("TweenService")
--In Order to Create A Tween, There are 3 components to it.
--[[
The part you want to tween,
The Tween Info,
The Tween Goal
]]
--Your tween is not working because you are entering the wrong parameters for the tween.
--Here is the fixed tween
local tweenTime = 3 --Any number works, this is the second it takes for tween to complete.
local easingStyle = Enum.EasingStyle.Linear --This is how the tween will move to get to its direction
local easingDirection = Enum.EasingDirection.InOut
tween:Create(b, TweenInfo.new(tweenTime, easingStyle, easingDirection), {Position = workspace.goal1.Position})
tween:Play()

0
ok ty fullguyblox3 69 — 2y
Ad

Answer this question