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

How do I pause a tween on when the person is not holding on the prompt?

Asked by 1 year ago
Edited 1 year ago

I have been trying to stop a tween when a player stops holding on the proximity prompt in a server side script. The tween mentioned is supposed to move a model of parts. I have tried making the variable global but it just returns me "Attempt to index nil with 'Pause'".

local TS = game:GetService("TweenService")

local board = script.Parent.BOARDPRIMARYPART
local isnotopen = script.Parent.isNotOpen.Value
local prompt = script.Parent["Movable Part"].ProximityPrompt

prompt.PromptButtonHoldBegan:Connect(function()


    local info = TweenInfo.new( prompt.HoldDuration, Enum.EasingStyle.Sine, Enum.EasingDirection.In )

    if isnotopen == true then

        local goal = {

            CFrame = CFrame.new(-224.431, 6.377, -1040.187)

        }

        TS:Create(board, info, goal):Play()

        prompt.ActionText = "Push in"

        isnotopen = false

    else

        local goal = {

            CFrame = CFrame.new(-224.431, 6.377, -1026.812)

        }

        _G.tween = TS:Create(board, info, goal)

        _G.tween:Play()

        prompt.ActionText = "Pull out"
        isnotopen = true

    end

end)

prompt.PromptButtonHoldEnded:Connect(function()

    _G.tween:Pause()

end)

Answer this question