generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Moving selected bricks with a click detector?

Previous Thread :: Next Thread 
MasValiente is not online. MasValiente
Joined: 27 Oct 2013
Total Posts: 1967
02 Feb 2014 03:35 PM
I'm fairly new to Lua but I can understand little bits of pieces and change
pre-written scripts but I can't write my own.

I'm trying to be able to get a window with 7 parts to move up in sequence when a player clicks on it.
Anyone?
Report Abuse
jonesj627 is not online. jonesj627
Joined: 06 Oct 2010
Total Posts: 1496
02 Feb 2014 03:37 PM
parts = {}
for i = 1,7 do
local p = Instance.new("Part",workspace)
p.Parent = game.Workspace
table.insert(parts,p)
cd = Instance.new("ClickDetector",p)
cd.Clicked:connect(function()
for i,v in pairs(parts) do
v.CFrame = v.CFrame * CFrame.new(0,10,0)
end
end)
end
Report Abuse
jonesj627 is not online. jonesj627
Joined: 06 Oct 2010
Total Posts: 1496
02 Feb 2014 03:38 PM
parts = {}
for i = 1,7 do
local p = Instance.new("Part",workspace)
p.Parent = game.Workspace
p.Anchored = true
p.CFrame = p.CFrame * CFrame.new(i*5,0,0)
table.insert(parts,p)
cd = Instance.new("ClickDetector",p)
cd.Clicked:connect(function()
for i,v in pairs(parts) do
v.CFrame = v.CFrame * CFrame.new(0,10,0)
end
end)
end
Report Abuse
jonesj627 is not online. jonesj627
Joined: 06 Oct 2010
Total Posts: 1496
02 Feb 2014 03:42 PM
--forget what i said up there, This one works, i just tested it in solo
parts = {}
for i = 1,7 do
local p = Instance.new("Part",workspace)
p.Parent = game.Workspace
p.Anchored = true
p.CFrame = p.CFrame * CFrame.new(i*5,5,0)
table.insert(parts,p)
cd = Instance.new("ClickDetector",p)
cd.MouseClick:connect(function()
for i,v in pairs(parts) do
v.CFrame = v.CFrame * CFrame.new(0,10,0)
end
end)
end
Report Abuse
MasValiente is not online. MasValiente
Joined: 27 Oct 2013
Total Posts: 1967
02 Feb 2014 03:45 PM
@Jones,
thank you very much but it seems I'm doing something wrong. I have a click detector and the script placed inside the model. I'm pretty sure they have to go into a specific block but I'm not sure which one. All of the parts I named and put them into the script, but I'm not sure if that's right. Here's what I have:

parts = {P1, P2, P3, P4, P5, Glass, P6}
for i = 1,7 do
local p = Instance.new("Part",workspace)
p.Parent = game.Workspace
p.Anchored = true
p.CFrame = p.CFrame * CFrame.new(i*5,0,0)
table.insert(parts,p)
cd = Instance.new("ClickDetector",p)
cd.Clicked:connect(function()
for i,v in pairs(parts) do
v.CFrame = v.CFrame * CFrame.new(0,10,0)
end
end)
end
Report Abuse
MasValiente is not online. MasValiente
Joined: 27 Oct 2013
Total Posts: 1967
02 Feb 2014 03:47 PM
I just used your most recent script that you tested and it doesn't work either.
I'm doing something wrong for sure.
Report Abuse
secretidagent is not online. secretidagent
Joined: 07 Nov 2010
Total Posts: 1600
02 Feb 2014 03:48 PM
model = script.Parent
getparts = model:GetChildren()

for i=1,#getparts do
cd = Instance.new("ClickDetector",getparts[i])
cd.Clicked:connect(function()
for i=1,7 do
for i=1,#getparts do
getparts[i].CFrame = getparts[i].CFrame + Vector3.new(0,1,0)
end
end
end)
end
Report Abuse
jonesj627 is not online. jonesj627
Joined: 06 Oct 2010
Total Posts: 1496
02 Feb 2014 03:49 PM
that was just a example, but put a click detector in your selected bricks and
insert them into the table like i did, leave the table blank at first though.


then use the for i,v in pairs to move them up
Report Abuse
MasValiente is not online. MasValiente
Joined: 27 Oct 2013
Total Posts: 1967
02 Feb 2014 03:51 PM
:( not making sense to me. Can I get your skype or something?
Report Abuse
jonesj627 is not online. jonesj627
Joined: 06 Oct 2010
Total Posts: 1496
02 Feb 2014 03:55 PM
--put this script inside your model with your selected bricks, and just leave the script alone
parts = {}
mc = script.Parent:GetChildren()
for i,v in pairs(mc) do
if v.ClassName == "Part" then
table.insert(parts,v)
cd = Instance.new("ClickDetector",v)
cd.MouseClick:connect(function()
for i,v in pairs(parts) do
v.CFrame = v.CFrame * CFrame.new(0,3,0)
end
end)
end
end
Report Abuse
MasValiente is not online. MasValiente
Joined: 27 Oct 2013
Total Posts: 1967
02 Feb 2014 03:57 PM
Yay it works!
Problem being though, is that I would like it to "slide" in a sense and on second click go down.
Report Abuse
jonesj627 is not online. jonesj627
Joined: 06 Oct 2010
Total Posts: 1496
02 Feb 2014 04:03 PM
--put this script inside your model with your selected bricks, and just leave the script alone
parts = {}
direction = "slide"
mc = script.Parent:GetChildren()
for i,v in pairs(mc) do
if v.ClassName == "Part" then
table.insert(parts,v)
cd = Instance.new("ClickDetector",v)
cd.MouseClick:connect(function()
for i,v in pairs(parts) do
if direction == "slide" then
v.CFrame = v.CFrame * CFrame.new(3,0,0)
direction = "down"
elseif direction == "down" then
v.CFrame = v.CFrame * CFrame.new(0,-3,0)
direction = "slide"
end
end
end)
end
end
--this one would make the bricks slide on the x axis then on second click, make them go down, and then it resets
Report Abuse
MasValiente is not online. MasValiente
Joined: 27 Oct 2013
Total Posts: 1967
02 Feb 2014 04:15 PM
Great! Thank you very much.
If it's not too much to ask for, can you set it so they actually slide and don't just instantly change position? I've edited the script so that it fits perfectly:

parts = {}
direction = "slide"
mc = script.Parent:GetChildren()
for i,v in pairs(mc) do
if v.ClassName == "Part" then
table.insert(parts,v)
cd = Instance.new("ClickDetector",v)
cd.MouseClick:connect(function()
for i,v in pairs(parts) do
if direction == "slide" then
v.CFrame = v.CFrame * CFrame.new(0,1.3,0)
direction = "down"
elseif direction == "down" then
v.CFrame = v.CFrame * CFrame.new(0,-1.3,0)
direction = "slide"
end
end
end)
end
end

Report Abuse
MasValiente is not online. MasValiente
Joined: 27 Oct 2013
Total Posts: 1967
02 Feb 2014 04:27 PM
?
Report Abuse
MasValiente is not online. MasValiente
Joined: 27 Oct 2013
Total Posts: 1967
02 Feb 2014 04:47 PM
Also with that script, each time it's activated it creates a new ClickDetector in each part.
Report Abuse
jonesj627 is not online. jonesj627
Joined: 06 Oct 2010
Total Posts: 1496
02 Feb 2014 04:55 PM
i can't make them slide smoothly without some brick lag
Report Abuse
999kko is not online. 999kko
Joined: 05 May 2012
Total Posts: 235
02 Feb 2014 04:57 PM
Use wait()
Report Abuse
jonesj627 is not online. jonesj627
Joined: 06 Oct 2010
Total Posts: 1496
02 Feb 2014 04:58 PM
you'd still be able to see that they're moving 1 by 1
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image