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

Argument 2 missing or nil for TweenService:Create()?

Asked by 3 years ago

I have this script here that changes the tweens the Camera CFrame, but i can't create it. The info and tweenEnd arguments are coming from the server.

Local script:

local tween = game:GetService('TweenService')
local camera = workspace.CurrentCamera
camera.CameraType = 'Scriptable'

game.ReplicatedStorage.ChangeAllCameras.OnClientEvent:Connect(function(info, tweenEnd)
    local move = tween:Create(camera, info, tweenEnd)

    move:Play()
    print('Tween played')
end)

Server script:

local tween = game:GetService('TweenService')

local EStyle = Enum.EasingStyle
local EDirection = Enum.EasingDirection

local randomCFrame = CFrame.new(math.random(-100, 100), math.random(-100, 100), math.random(-100, 100), math.rad(math.random(-359, 360)), math.rad(math.random(-359, 360)), math.rad(math.random(-359, 360)), 0, 0, 0, 0, 0, 0)
local randomEasingStyle = math.random(0, 10)
local randomEasingDirection = math.random(0, 2)

while true do

    print('While loop started')

    wait(3)

    if randomEasingDirection == 0 then randomEasingDirection = EDirection.In elseif randomEasingDirection == 1 then randomEasingDirection = EDirection.Out elseif randomEasingDirection == 2 then randomEasingDirection = EDirection.InOut end

    if randomEasingStyle == 0 then randomEasingStyle = EStyle.Back elseif randomEasingStyle == 1 then randomEasingStyle = EStyle.Bounce elseif randomEasingStyle == 2 then randomEasingStyle = EStyle.Circular elseif randomEasingStyle == 3 then randomEasingStyle = EStyle.Cubic elseif randomEasingStyle == 4 then randomEasingStyle = EStyle.Elastic elseif randomEasingStyle == 5 then randomEasingStyle = EStyle.Exponential elseif randomEasingStyle == 6 then randomEasingStyle = EStyle.Linear elseif randomEasingStyle == 7 then randomEasingStyle = EStyle.Quad elseif randomEasingStyle == 8 then randomEasingStyle = EStyle.Quint elseif randomEasingStyle == 9 then randomEasingStyle = EStyle.Quart elseif randomEasingStyle == 10 then randomEasingStyle = EStyle.Sine end
    tweenEnd = {CFrame = randomCFrame}
    local info = TweenInfo.new(
        3,
        randomEasingStyle,
        randomEasingDirection,
        0,
        false,
        0
    )

    game.ReplicatedStorage.ChangeAllCameras:FireAllClients(info, tweenEnd)

    print('All clients fired')

    randomCFrame = CFrame.new(math.random(-100, 100), math.random(-100, 100), math.random(-100, 100), math.rad(math.random(-359, 360)), math.rad(math.random(-359, 360)), math.rad(math.random(-359, 360)), 0, 0, 0, 0, 0, 0)
    randomEasingStyle = math.random(0, 10)
    randomEasingDirection = math.random(0, 2)

    print(randomCFrame)
    print(randomEasingStyle)
    print(randomEasingDirection)

end

Argument 2 is the tween info.

1 answer

Log in to vote
1
Answered by
gskw 1046 Moderation Voter
3 years ago

You're hitting a rather annoying piece of undocumented behaviour in Roblox: you can't pass TweenInfo over RemoteEvents. In fact, it is automatically turned into nil if you try it. Instead, you can collect the arguments for the TweenInfo into a table and pass them over the network:

Server script:

  local info = {
        3,
        randomEasingStyle,
        randomEasingDirection,
        0,
        false,
        0
    } -- Pass it as a table

    game.ReplicatedStorage.ChangeAllCameras:FireAllClients(info, tweenEnd)

Local script:

game.ReplicatedStorage.ChangeAllCameras.OnClientEvent:Connect(function(info, tweenEnd)
    -- Info is a table, containing the arguments for the TweenInfo constructor. We unpack them here.
    local move = tween:Create(camera, TweenInfo.new(unpack(info)), tweenEnd)

    move:Play()
    print('Tween played')
end)
0
Ah, I understand. I'll try it. deeskaalstickman649 475 — 3y
Ad

Answer this question