Hey! I’m trying to tween a SnowPlow that is welded to a vehicle. The “SnowDown” tween works perfectly, however, the “SnowUp” doesn’t tween at all (other parts like the hydraulicsSound work).
I’ve tried numerous ideas, but I wasn’t able to fix this issue. Any idea?
ServerScript
local plowUpPart = car:WaitForChild("Body").SnowPlow.UP
local plowDownPart = car:WaitForChild("Body").SnowPlow.Down
local upWeld, downWeld, C1upWeld
for _, weld in pairs(car:WaitForChild("DriveSeat"):GetChildren()) do
if weld.Name == "UP" and weld.Active then
upWeld = weld
C1upWeld = upWeld
elseif weld.Name == "Down" and weld.Active then
downWeld = weld
end
end
if not upWeld or not downWeld then
return
end
local tweenInfo = TweenInfo.new(2.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
if argument == "SnowDown" then
local goal = {C1 = downWeld.C1}
local tween = TweenService:Create(upWeld, tweenInfo, goal)
tween:Play()
plowUpPart:SetAttribute("plowPosition", "Down")
playHydraulicsSound()
elseif argument == "SnowUp" then
local goal = {C1 = C1upWeld.C1}
local tween = TweenService:Create(upWeld, tweenInfo, goal)
tween:Play()
plowUpPart:SetAttribute("plowPosition", "Up")
playHydraulicsSound()
end
local plowUpPart = car:WaitForChild("Body").SnowPlow.UP
local plowDownPart = car:WaitForChild("Body").SnowPlow.Down
local upWeld, downWeld, C1upWeld
local upWeldC1,downWeldC1
for _, weld in pairs(car:WaitForChild("DriveSeat"):GetChildren()) do
if weld.Name == "UP" and weld.Active then
upWeld = weld
C1upWeld = upWeld
elseif weld.Name == "Down" and weld.Active then
downWeld = weld
end
end
upWeldC1 = upWeld.C1
downWeldC1 = downWeld.C1
if not upWeld or not downWeld then
return
end
local tweenInfo = TweenInfo.new(2.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
if argument == "SnowDown" then
local goal = {C1 = downWeldC1}
local tween = TweenService:Create(upWeld, tweenInfo, goal)
tween:Play()
plowUpPart:SetAttribute("plowPosition", "Down")
playHydraulicsSound()
elseif argument == "SnowUp" then
local goal = {C1 = upWeldC1}
local tween = TweenService:Create(upWeld, tweenInfo, goal)
tween:Play()
plowUpPart:SetAttribute("plowPosition", "Up")
playHydraulicsSound()
end
Interesting. I think I know the issue a bit but it’s because C1upWeld just happens to be your weld. You need to save the weld values prior to tweening the weld.
Also why not use the Attribute of the plowPosition Up or Down to select which way the input changes the plow direction. It saves you setting up another variable that you’re duplicating.
if plowUpPart.Attribute = "Up" then
-- code to move plow down
else
-- code to move plow up
end
Where are you setting the variable argument for the if check?
If my suggestions do not work try printing your upWeld.C1 and downWeld.C1 variable values in their respective sections of the code to see if they are both equal to the same value.
Weird, new computer and it's giving me strange text with the use of single quote marks and backticks...
No, that’s not the issue, or at least shouldn’t be. The function checks for welds that are named “UP” (or “Down” in the other case) and that are Active. Then it sets that weld it finds to the variable.
Also I’m getting the argument from an event, the script that I provided is not full. However, you’re right that I can just use the attribute.
So did you try saving the values before manipulating everything?
Because I think the issue works like this:
local tweenInfo = TweenInfo.new(2.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
if argument == "SnowDown" then
local goal = {C1 = downWeld.C1} -- snow plow goes down, pretty nice!
local tween = TweenService:Create(upWeld, tweenInfo, goal)
tween:Play()
plowUpPart:SetAttribute("plowPosition", "Down")
playHydraulicsSound()
elseif argument == "SnowUp" then
local goal = {C1 = C1upWeld.C1} -- do remember, we set C1upWeld to our "upWeld"
local tween = TweenService:Create(upWeld, tweenInfo, goal) -- oh no, doesn't work!! Why? because the goal is set to our current upWeld's C1. It needs to be the old one.
tween:Play()
plowUpPart:SetAttribute("plowPosition", "Up")
playHydraulicsSound()
end
That’s the issue, I can’t tween the CFrame. Wanted to do it, but it can only tween if the part is anchored. However, as it’s a vehicle, it obviously cannot be anchored and needs to be welded to the car. Welds then don’t have a CFrame property, so that’s why I need to do this.
Last time I checked they were just (obviously) the same, or very similar values, not sure about now, I changed parts of the code quite a lot beforehand.
You’re using welds to only rotate the plow right? Not move it or anything correct?
If so, then you can use HingeConstraints with their AcutatorType set to Servo.
This way, you can easily manipulate the angles without having to use welds.
You’re not wrong here. I wanted to suggest an alternative because the issue is a bit weird? Like I suspect it to be fixed by properly assigning upWeld and such, yet it doesn’t work.
local plowUpPart = car:WaitForChild("Body").SnowPlow.UP
local plowDownPart = car:WaitForChild("Body").SnowPlow.Down
local upWeld
local upWeldC1,downWeldC1
for _, weld in pairs(car:WaitForChild("DriveSeat"):GetChildren()) do
if weld.Name == "UP" and weld.Active then
upWeld = weld
upWeldC1 = weld.C1
elseif weld.Name == "Down" and weld.Active then
downWeldC1 = weld.C1
end
end
if not upWeld or not downWeldC1 then
return
end
local tweenInfo = TweenInfo.new(2.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
local goal
if argument == "SnowDown" then
goal = {C1 = downWeldC1}
plowUpPart:SetAttribute("plowPosition", "Down")
elseif argument == "SnowUp" then
goal = {C1 = upWeldC1}
plowUpPart:SetAttribute("plowPosition", "Up")
end
local tween = TweenService:Create(upWeld, tweenInfo, goal)
tween:Play()
playHydraulicsSound()