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

How do you make a Model move Right to Left by clicking?

I am trying to make a script that basically leads to you clicking a Model. Once the model is clicked it will move Left or if it was already left it would be Right, I tried going through the wiki but still having trouble. If you can please help me out. Thanks.

2 answers

to do that, you would firstly need to know exactly between wich two coordinates a part of the model should move. we will base the script on that. only 1 of the 3 coordinates should be different.

you will probably need to do some adjustments, but imagine your part moves between (10,0,0) and (20,0,0). that would mean the X coordinate needs to change (coordinates are X,Y,Z) then you do this. i will make the script based on having a clickdetector.

-- i especially made this script for easy configuring.  simply change the variables at the top to fit your part.  if the Coordinate is Y or Z, only change Position.X at line 3  to Position.Y or Position.Z. just keep the variable X to spare yourself time.


local speed =  0.07 -- how much the brick moves each tick
local waittime = 0.25 --How much time there is between each tick.
X = Workspace.Model.Part.Position.X -- make sure this is the brick you based coordinates on.
minpos = 10 --Minimum position, this is 10 in this case
maxpos = 20 --Maximum position, this is 20 in this case
model = Workspace.Model --the model you want to move.

function clicked()
if X < maxpos then 
While X  < maxpos do 
model:MoveTo(X + Vector3.new(speed,0,0))
X = X --Update the Variable
if X > maxpos then x = maxpos --Check, to make sure it won't outpass its limit on the last tick.
end
wait(waittime)
end
else
While X  > minpos do 
model:MoveTo(X - Vector3.new(speed,0,0))
X = X -- update the variable.
if X < minpos then x = minpos --Check, to make sure it won't outpass its limit on the last tick.
end
wait(waittime)
end
end
Workspace.Model.Part.ClickDetector:connect(clicked) -- Clickdetectors can only be used in parts. so those wich brick should be clicked wisely

1 comment

0

Oh thank you that was helpful I get it a bit more now but how could I fix line 12?

The way I would do it is to check it's cords, then if it's == to the last position then move it to the next.. If you need me to set up a base script for you then I will.

1 comment

0

I'm using a If open == but it's still confusing to me, I would be thankful if you did help me out with the base script.

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