Hello everyone! So i’ve got a problem where a part tweens to the wrong position.
The video above shows that the part isn’t tweening to the right position and it is supposed to tween to the position of a other part.
script:
local LaserSphere = script.Parent
local Laser = script.Parent.Laser
local ShotParticle = script.Parent.LaserChargePart.ShotParticles
local laserChargePart = script.Parent.LaserChargePart
local tweenService = game:GetService("TweenService")
local Destination = Vector3.new(LaserSphere.Position.X, 11.078, LaserSphere.Position.Z) -- The position where the part needs to tween to
local SizeDestination = Vector3.new(9.1, 0.4, 0.4)
local DestinationInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false)
local SizeDestinationInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false)
local DestinationTween = tweenService:Create(Laser, DestinationInfo, {Position = Destination})
local SizeTween = tweenService:Create(Laser, SizeDestinationInfo, {Size = SizeDestination})
local MoveValue = script.Parent.MoveValue
while wait(1) do
if MoveValue.Value == true then
DestinationTween:Play()
SizeTween:Play()
end
end
Is the sphere anchored? The code work perfectly fine. Is the sphere position off?
Also the while wait() do i think it is too much. Since you are going to play the tween when the value change how about use Value.Change instead.
local LaserSphere = workspace.Sphere
local Laser = workspace.Lazer
--local OldPosition = Laser.Position
--local OldSize = Laser.Size
local MoveValue = workspace:WaitForChild("MoveValue")
MoveValue.Changed:Connect(function()
local LaserSphere = workspace.Sphere
local Laser = workspace.Lazer
--local ShotParticle = script.Parent.LaserChargePart.ShotParticles
--local laserChargePart = script.Parent.LaserChargePart
local tweenService = game:GetService("TweenService")
local Destination = Vector3.new(LaserSphere.Position.X, 11.078, LaserSphere.Position.Z) -- The position where the part needs to tween to
local SizeDestination = Vector3.new(9.1, 0.4, 0.4)
local DestinationInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false)
local SizeDestinationInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false)
local DestinationTween = tweenService:Create(Laser, DestinationInfo, {Position = Destination})
--local DestinationTweenBack = tweenService:Create(Laser, DestinationInfo, {Position = OldPosition})
local SizeTween = tweenService:Create(Laser, SizeDestinationInfo, {Size = SizeDestination})
--local SizeTweenBack = tweenService:Create(Laser, SizeDestinationInfo, {Size = OldSize})
if MoveValue.Value == true then
DestinationTween:Play()
SizeTween:Play()
elseif MoveValue.Value == false then
--DestinationTweenBack:Play()
--SizeTweenBack:Play()
end
end)
By calling the LaserSphere and Lazer in function, this will prevent setting position wrong as it will update position everytime the Value change.
(Ignore those tweenback stuff i just add for fun)
As the sphere moves, your Destination variable stays constant. The solution would be to include the variables inside the while wait() loop, to keep the variables updated.
local LaserSphere = script.Parent
local Laser = script.Parent.Laser
local ShotParticle = script.Parent.LaserChargePart.ShotParticles
local laserChargePart = script.Parent.LaserChargePart
local tweenService = game:GetService("TweenService")
while wait(1) do
local Destination = Vector3.new(LaserSphere.Position.X, 11.078, LaserSphere.Position.Z) -- The position where the part needs to tween to
local SizeDestination = Vector3.new(9.1, 0.4, 0.4)
local DestinationInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false)
local SizeDestinationInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false)
local DestinationTween = tweenService:Create(Laser, DestinationInfo, {Position = Destination})
local SizeTween = tweenService:Create(Laser, SizeDestinationInfo, {Size = SizeDestination})
local MoveValue = script.Parent.MoveValue
if MoveValue.Value == true then
DestinationTween:Play()
SizeTween:Play()
end
end