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

Moving a Model Using a TextButton?

local model = game.Workspace.Section
model.PrimaryPart = model.MainPart
local position = model.PrimaryPart

script.Parent.MouseButton1Click:Connect(function() -- this is linked to the TextButton located inside starterGUI
	
	while wait(0.001) do
	model:MoveTo(position.Position + Vector3.new(3,0,0))
	end
	end)

I'm not getting an error but the model doesn't move when I create a Button1Click function, if I remove the function it works perfectly fine. So I'm not sure why the function is preventing the loop from executing

2 answers

local model = game.Workspace.Section
model.PrimaryPart = model.MainPart
local position = model.PrimaryPart
local move = false

local function moveModel(stat)
	if stat == true then
		-- move
		while move do
			wait(.01)
			model:MoveTo(position.Position + Vector3.new(3,0,0))
		end
	else return
	end
end

script.Parent.MouseButton1Click:Connect(function()
	move = not move
	moveModel(move)
end)

1 comment

0

Apologies for not giving a more thorough explanation. What I'm trying to do is move a model using a Gui Button rather than a click detector, but it seems like the function doesn't detect anything. The answer above also didn't execute but didn't have any errors^

You can set it a whole new vector3 value while using its original axis coordinates.

local model = game.Workspace.Section
model.PrimaryPart = model.MainPart
local position = model.PrimaryPart

script.Parent.MouseButton1Click:Connect(function() -- this is linked to the TextButton located inside starterGUI

    while wait(0.001) do
    model:MoveTo(position.Position=Vector3.new(position.Position.X+3,position.Position.Y,position.Position.Z))
    end
    end)

2 comments

0

This didn't work either, even after fixing the error on line 08, function still doesn't seem to detect the loop inside of it.

0

I think I can fix this

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