Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I use MoveTo and still protect the Weld?[SOLVED]

Hey everyone-- So today I am trying to spawn in a model from lighting, and then use the MoveTo function to move the model to the correct position. The problem occurs when I click the button that begins the functions. The Model spawns just fine and goes to the correct position but then something goes wrong with the Welding script and it falls apart and is unusable. I know the problem is with the MoveTo function and everything works smoothly when I run it in solo mode in studio. Any help would be enormously appreciated. I've included the spawn-in script and the weld script.

Spawn Script

local debounce = false

local everything = {model}
local names = {model}

local children = game.Lighting:children()
for i=1,#children do
	if (children[i].Name == "RowBoat") then
		table.insert(everything, children[i]:clone())
		table.insert(names, children[i].Name)
	end
end
------------------------------------------------------------------------------
function regen()
	if game.Workspace.Slot1.Value == 0 then
		wait(2)
	for i=1,#everything do
		game.Lighting:findFirstChild(names[i]):clone()
		new_thing = everything[i]:clone()
		new_thing.Parent = game.Workspace
		new_thing:makeJoints()
		new_thing:MoveTo (Vector3.new(0,5,70))--This is the MoveTo stuffins
		new_thing.VehicleSeat.Position = Vector3.new(-2.1,17.1,0)
	end
	
	else if game.Workspace.Slot2.Value == 0 then
		wait(2)
	for i=1,#everything do
		game.Lighting:findFirstChild(names[i]):clone()
		new_thing = everything[i]:clone()
		new_thing.Parent = game.Workspace
		new_thing:makeJoints()
		new_thing:MoveTo (Vector3.new(0,5,130))
		new_thing.VehicleSeat.Position = Vector3.new(-2.1,17.1,50)
	end
	
	else
			return
		end
	end
end

script.Parent.MouseButton1Down:connect(regen)

Weld script

function Weld(x,y)
	local W = Instance.new("Weld")
	W.Part0 = x
	W.Part1 = y
	local CJ = CFrame.new(x.Position)
	local C0 = x.CFrame:inverse()*CJ
	local C1 = y.CFrame:inverse()*CJ
	W.C0 = C0
	W.C1 = C1
	W.Parent = x
end

function Get(A)
	if (A.className == "Part") or (A.className == "Seat") or (A.className == "WedgePart") or (A.className == "CornerWedgePart") or (A.className == "VehicleSeat") then
		Weld(script.Parent.Engine, A)
	else
		local C = A:GetChildren()
		for i=1, #C do
		Get(C[i])
		end
	end
end

function Finale()
	Get(script.Parent)
end

Finale()

NEWEST UPDATE: I just changed a script to a regular script instead of a local one. All is well in the world again.

2 comments

0

Any help? I am thinking about just anchoring the model, moving it over, then enabling the weld script and unachoring the model.

0

This I found out, does not work.

1 answer

UPDATE:

I've narrowed down the problem even further. The MoveTo function is not what is causing the mishap. I have a script that does the exact same thing but it functions as a button you touch with your character. The only difference between the two different tests is that one uses a button GUI and another used a block-button. I have to conclude that somehow the GUI button is somehow messing things up. I just can't tell why it does so. Below is the spawn script from the brick-button.

local box = script.Parent


local debounce = false



local everything = {model}
local names = {model}

local children = game.Lighting:children()
for i=1,#children do
	if (children[i].Name == "RowBoat") then
		table.insert(everything, children[i]:clone())
		table.insert(names, children[i].Name)
	end
end


function regen()
	wait(2)
	for i=1,#everything do
		game.Lighting:findFirstChild(names[i]):clone() -- Dont mess with this!
		new_thing = everything[i]:clone()
		new_thing.Parent = game.Workspace
		new_thing:makeJoints()
		new_thing:MoveTo (Vector3.new(0,5,70))--THIS IS NEW
		new_thing.VehicleSeat.Position = Vector3.new(-2.1,17.1,0)--Moves the seat into the body
		
	end
end

function onTouched(hit)
	local humanoid = hit.Parent:findFirstChild("Humanoid") -- Not too important
	if humanoid~=nil and debounce == false then
		debounce = true
		
		script.Parent.BrickColor = BrickColor.new(26)

		regen()
		wait(10)


		script.Parent.BrickColor = BrickColor.new(104)


		debounce = false
	end
end


script.Parent.Touched:connect(onTouched)

1 comment

0

Hmm, I still cant get it to work. I think I am just going to completely remake it.

This discussion is preserved as it was. New answers, comments, and votes are closed.