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

how can i make my tweenservice work every time?

Asked by 4 years ago
Edited 4 years ago

script:

local tweenservice = game.TweenService
local right = game.Workspace.carshopdoors.carshoprightdoor
local left = game.Workspace.carshopdoors.carshopleftdoor

local tweenstyle = TweenInfo.new(
    1,
    Enum.EasingStyle.Linear,
    Enum.EasingDirection.Out,
    0,
    false,
    0
)
local leftdoorclose = {
    CFrame = CFrame.new(-187.32, 6.1, -1216.665),
    Rotation = Vector3.new(0, 20, 0)
}
local rightdoorclose = {
    CFrame = CFrame.new(-184.71, 6.1, -1209.494),
    Rotation = Vector3.new(0, 20, 0)
}
local leftdooropen = {
    CFrame = CFrame.new(-184.764, 6.1, -1221.919),
    Orientation = Vector3.new(0, -70, 0)
}
local rightdooropen = {
    CFrame = CFrame.new(-179.131, 6.1, -1206.973),
    Orientation = Vector3.new(0, -70, 0)
}

local leftclose = tweenservice:Create(left,tweenstyle,leftdoorclose)
local rightclose = tweenservice:Create(right,tweenstyle,rightdoorclose)
local leftopen = tweenservice:Create(left,tweenstyle,leftdooropen)
local rightopen = tweenservice:Create(right,tweenstyle,rightdooropen)
local active = true
script.Parent.Touched:Connect(function()
    if active then
        active = false
        print("working")
    leftopen:Play()
    rightopen:Play()
    wait(2)
    active = true
    end
end)

sometimes it goes like this https://imgur.com/a/dCggpAZ

other times it goes like this https://imgur.com/a/iFDhsuG

how can i make it always work as https://imgur.com/a/iFDhsuG

1 answer

Log in to vote
1
Answered by
sleazel 1287 Moderation Voter
4 years ago
Edited 4 years ago

EDIT: Math error

CFrames are complete coordinate frame of an object in the game, so they set orientation too, every time you use CFrame.new. That means you do not really need to tween orientation as well. Also that is probably why you have issues with your doors. I will amend your script to use CFrame only. I assume that the door wings are closed at the start of the game.

local tweenservice = game.TweenService
local right = game.Workspace.carshopdoors.carshoprightdoor
local left = game.Workspace.carshopdoors.carshopleftdoor

local tweenstyle = TweenInfo.new(
    1,
    Enum.EasingStyle.Linear,
    Enum.EasingDirection.Out,
    0,
    false,
    0
)
local leftdoorclose = {
    CFrame = left.CFrame --just remember starting position.
}
local rightdoorclose = {
    CFrame = right.CFrame
}
local leftdooropen = {
    CFrame = (left.CFrame + Vector3.new(2.556,0,-5.254)) * CFrame.Angles(0,math.rad(90),0)
-- it is beter to use relative values, so you can make easy copies if you need to

}
local rightdooropen = {
    CFrame = (right.CFrame + Vector3.new(5.579,0,2.521)) * CFrame.Angles(0,math.rad(-90),0)
}

local leftclose = tweenservice:Create(left,tweenstyle,leftdoorclose)
local rightclose = tweenservice:Create(right,tweenstyle,rightdoorclose)
local leftopen = tweenservice:Create(left,tweenstyle,leftdooropen)
local rightopen = tweenservice:Create(right,tweenstyle,rightdooropen)
local active = true
script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("HumanoidRootPart") then --add a humanoid check to prevent door self activating.
        if active then
            active = false
            print("working")
        leftopen:Play()
        rightopen:Play()
        wait(2)
        active = true
        end
    end
end)

Have a nice scripting session.

0
but here is the problem for me, whenever i use CFrame.Angles my part always get moved to the spawn where the position is 0,0,0 and thats why i use Orientation Gameplayer365247v2 1055 — 4y
0
Have you tried my code? sleazel 1287 — 4y
0
just got home to try it and it works thanks Gameplayer365247v2 1055 — 4y
0
now my question is, how can i reverse this Gameplayer365247v2 1055 — 4y
View all comments (3 more)
0
do you want the doors to close automatically? sleazel 1287 — 4y
0
i made them fully work the way i want both ways and with your script it just breaks as soon as i use the other activator Gameplayer365247v2 1055 — 4y
0
if the other activator is in the same script, you would use leftclose:Play() and rightclose:Play(). Similiary in other script, just remember when doors were at the start of the game (memorize CFrame) and just play tween. It will GUARANTEE to tween to where it was at the start of the game and with proper orientation. sleazel 1287 — 4y
Ad

Answer this question