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

Non-Smooth lerp movement on Cylinder. Any fixes?

Asked by 6 years ago

I believe the problem lies where I have to change the position of the cylinder as a move, is there any possible way of fixing it?

local beam = script.Parent.Parent.Parent.Beam
local online = true
local button = script.Parent.CD
local debounce = false

local distance = 16

local red = Color3.fromRGB(196, 40, 28)
local green = Color3.fromRGB(46, 204, 113)
local busy = Color3.fromRGB(44, 62, 80)

local stSize, enSize = Vector3.new(0.05, 0.34, 0.68), Vector3.new(20.3, 0.34, 0.68)
local stPos, enPos = Vector3.new(167.036, 3.199, 81.318), Vector3.new(167.036, 3.199, 91.443)

button.MouseClick:Connect(function()
    if debounce == false then
        debounce = true
        button.MaxActivationDistance = 0 -- Disable Click
        button.Parent.Color = busy -- Set Colour

        if online == true then
            for i=0,1,0.05 do
                beam.Size = beam.Size:Lerp(stSize, i)
                beam.Position = beam.Position:Lerp(stPos, i)
                wait(0.1)
            end
            online = false
            button.Parent.Color = green
        else
            for i=0,1,0.1 do
                beam.Size = beam.Size:Lerp(enSize, i)
                beam.Position = beam.Position:Lerp(enPos, i)
                wait(0.05)
            end
            online = true
            button.Parent.Color = red
        end

        button.MaxActivationDistance = distance -- Reset Click
        debounce = false
    end
end)
0
Do you have discord? casper123123123 357 — 6y
0
Yes I do User#16405 0 — 6y
0
Wouldn't have minded you giving it. Anyway's what is it. casper123123123 357 — 6y
0
I'm on the Scripting Helpers discord User#16405 0 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago

You are using a Deprecated function. Not sure if it says it but I found a screenshot of a staff saying so. Anyway's here is a functional version of your code using Tween Service. I also recommend you check out Tween Service for yourself! As it is very useful.

local TweenService = game:GetService("TweenService")
local Beam = game.Workspace.Beam
local Button = script.Parent
local ClickDetector = Button.CD
local debounce = false
local Activated = false
local Distance = 16

local ColorRed = Color3.fromRGB(196, 40, 28)
local ColorGreen = Color3.fromRGB(46, 204, 113)
local ColorWhenBusy = Color3.fromRGB(44, 62, 80)

local StartingSize, EndingSize = Vector3.new(0.05, 0.34, 0.68), Vector3.new(20.3, 0.34, 0.68)
local StartingPos, EndingPos = Vector3.new(167.036, 3.199, 81.318), Vector3.new(167.036, 3.199, 91.443)

local TweeningInformation = TweenInfo.new(
    0.5, -- Time it takes to tween
    Enum.EasingStyle.Linear,
    Enum.EasingDirection.Out,
    0, -- Times it will repeat
    false -- Should tween repeat
)
local PartProperties = {
    Size = Vector3.new(0.05, 0.34, 0.68),
    Position = Vector3.new(167.036, 3.199, 81.318)
}
local ReversePartProperties = {
    Size = Vector3.new(20.3, 0.34, 0.68),
    Position = Vector3.new(167.036, 3.199, 91.443)
}

ClickDetector.MouseClick:Connect(function()
    if debounce == false then
        debounce = true

        ClickDetector.MaxActivationDistance = 0 -- Disable Click
        Button.Color = ColorWhenBusy -- Set Colour

        if Activated == true then
            Activated = false
            Button.Color = ColorGreen
            local Tween = TweenService:Create(Beam,TweeningInformation,PartProperties)
            Tween:Play()
            else
            local Tween = TweenService:Create(Beam,TweeningInformation,ReversePartProperties)
            Tween:Play()
            Activated = true
            Button.Color = ColorRed
        end

        ClickDetector.MaxActivationDistance = Distance -- Reset Click
        debounce = false
    end
end)
Ad

Answer this question