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

How do I make a Part that when I click it it changes its position?

I tried this but it doesn't seem to work. Please help me!

script.Parent.ClickDetector.MouseClick:Connect(function()
	script.Parent.Position = Vector3.new(1.781, 0.5, 35.84)
end)

2 comments

1

Is there a Weld in the part? Or something similar?

0

Yeah, thanks, didn't notice I had it lmao, now write that as an answer so that I can accept you

3 answers

Put this in a server script and you're good to go.

2 comments

0

It won't work. Then you would have to edit the script. Cause then the parent would be serverscriptservice.

0

You can put server scripts in other places besides serverscriptservice lol.

Everything works! Just make sure there is no weld.

I would recommend making a loop so it changes multiple times. Like this.

while wait() do
	script.Parent.ClickDetector.MouseClick:Connect(function()
	end)
end

Otherwise, everything is good!

Also, make sure the click detector exists and the script's parent is the part.

1 comment

0

Sorry, what's the point of the infinite loop? So what changes multiple times?

You could just use CFrame for this, it's easier and more simple. This script needs to be put INSIDE the part.

As said by other users, please make sure there are no welds stopping it from moving.

Random Select Position:

local Positions = { 
{1.781, 0.5, 35.84}, 
{1.6, 0.5, 35} 
}

--[[
Made a table supposing it was RANDOM, I'll give another example of a precise CFrame.
]]

local function GetRandomPosition()
  return Positions[math.random(1, #Positions)]
end

local function OnClick()
  local Part = script.Parent
  local CD = Part:WaitForChild("ClickDetector") -- checks if it has a clickdetector

  Part.CFrame = CFrame.new(Vector3.new(GetRandomPosition()))
end

script.Parent:WaitForChild("ClickDetector").MouseClick:Connect(OnClick)

Specific Position:

local function OnClick()
  local Part = script.Parent
  local CD = Part:WaitForChild("ClickDetector") -- checks if it has a clickdetector

  Part.CFrame = CFrame.new(Vector3.new(1.781, 0.5, 35.84)
end

script.Parent:WaitForChild("ClickDetector").MouseClick:Connect(OnClick)

lmk if this works, hope it does.

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