I have an issue with a Roblox script. This script is supposed make an object fly with a constant speed in the air but it doesn't work correctly. My programming knowledge about the Lua programming language is limited. When the Roblox game begins, the object immediately falls down. How can I fix this issue? Any help would be appreciated.
local All = script.Parent.Model:GetChildren()
for A = 1,#All do
if All[A].Name ~= "Main" then
local NewWeld = Instance.new("Weld")
NewWeld.Name = "Weld"
NewWeld.Part0,NewWeld.Part1 = All[A],script.Parent.Model.Main
NewWeld.C0 = All[A].CFrame:inverse()
NewWeld.C1 = script.Parent.Model.Main.CFrame:inverse()
NewWeld.Parent = script.Parent.Model.Main
end
end
local NewWeld = Instance.new("Motor6D")
NewWeld.Name = "Motor6D"
NewWeld.Part0,NewWeld.Part1 = script.Parent.Model.Main,script.Parent.Ref
NewWeld.C0 = script.Parent.Model.Main.CFrame:inverse()
NewWeld.C1 = script.Parent.Ref.CFrame:inverse()
NewWeld.Parent = script.Parent.Ref
while true do
game:GetService("TweenService"):Create(NewWeld,TweenInfo.new(2,0),
{C1 = script.Parent.Ref.CFrame:inverse()*CFrame.new(75,0,0)}):Play()
wait(5)
game:GetService("TweenService"):Create(NewWeld,TweenInfo.new(2,0),
{C1 = script.Parent.Ref.CFrame:inverse()*CFrame.new(0,0,0)}):Play()
wait(2)
end
It could be that script.Parent.Ref is unanchored. Try anchoring the object or use:
script.Parent.Ref.Anchored = true