digpoe
|
  |
| Joined: 02 Nov 2008 |
| Total Posts: 9092 |
|
|
| 29 Jan 2013 10:15 AM |
I have this script to make buttons, and when one of those buttons are pressed it clones a part into CurrentCamera for a player to position. The script works fine on the first try, but it seems to only clone and not do any moving of the part the second time. Any ideas why this seems to happen?
Here's the script. It's a localscript.
local button local size = UDim2.new(0.2, 0, 0.04, 0) local pos = UDim2.new(0, 0, 0 ,0) int = 0 local currcam = workspace.CurrentCamera for _, v in pairs(game.Lighting.insertParts:GetChildren()) do button = Instance.new("TextButton", script.Parent.Parent.Parent.things) button.Size = size button.Position = pos pos = pos + UDim2.new(0.2, 0, 0, 0) if int == 5 then pos = pos + UDim2.new(0, 0, 0.04, 0) int = 0 end int = int + 1 button.Text = v.Name button.TextColor3 = Color3.new(1, 1, 1) button.Style = "RobloxButtonDefault" end button.MouseButton1Down:connect( function() local mouse = game.Players.LocalPlayer:GetMouse() local clone = game.Lighting.insertParts[button.Text]:Clone() clone.Parent = currcam clone.Transparency = 0.5 mouse.TargetFilter = clone dragging = true wait() while dragging do clone.Position = Vector3.new(math.floor(mouse.Hit.p.X), math.floor(mouse.Hit.p.Y), math.floor(mouse.Hit.p.Z)) wait() mouse.Button1Down:connect(function() dragging = false clone.Transparency = 0 clone.Parent = workspace end) end end ) |
|
|
| Report Abuse |
|
|
digpoe
|
  |
| Joined: 02 Nov 2008 |
| Total Posts: 9092 |
|
|
| 29 Jan 2013 10:51 AM |
| Bump. This only works once, and I am not sure why. |
|
|
| Report Abuse |
|
|
Combrad
|
  |
| Joined: 18 Jul 2009 |
| Total Posts: 11025 |
|
|
| 29 Jan 2013 11:33 AM |
Why would you possibly need to use :GetMouse() more than once. That should solve your problem. |
|
|
| Report Abuse |
|
|
digpoe
|
  |
| Joined: 02 Nov 2008 |
| Total Posts: 9092 |
|
|
| 29 Jan 2013 11:35 AM |
I've tried it outside of the buttondown function, and it still doesn't seem to work the second time. There's no erros if you're wondering.
|
|
|
| Report Abuse |
|
|
Combrad
|
  |
| Joined: 18 Jul 2009 |
| Total Posts: 11025 |
|
|
| 29 Jan 2013 12:48 PM |
That's my point.
local mouse = player:GetMouse() local mouseActive = false
then when you want to 'activate' the mouse, set mouseActive to true, and deactivate set it to false, then just run checks with a statement. |
|
|
| Report Abuse |
|
|
digpoe
|
  |
| Joined: 02 Nov 2008 |
| Total Posts: 9092 |
|
|
| 30 Jan 2013 09:37 AM |
That's not it.
:GetMouse() doesn't work the 2nd time. I don't want to mess with uneeded booleans. |
|
|
| Report Abuse |
|
|
Combrad
|
  |
| Joined: 18 Jul 2009 |
| Total Posts: 11025 |
|
|
| 30 Jan 2013 10:41 AM |
If :GetMouse() only works once, then only use it once. Simple. As. |
|
|
| Report Abuse |
|
|
digpoe
|
  |
| Joined: 02 Nov 2008 |
| Total Posts: 9092 |
|
|
| 30 Jan 2013 10:42 AM |
I want it to be used more than once. That's the thing. I want a player to be able to put the part in more than one time. |
|
|
| Report Abuse |
|
|
Combrad
|
  |
| Joined: 18 Jul 2009 |
| Total Posts: 11025 |
|
|
| 30 Jan 2013 10:44 AM |
Try it, I bet I am right.
local button local mouse = game.Players.LocalPlayer:GetMouse() local size = UDim2.new(0.2, 0, 0.04, 0) local pos = UDim2.new(0, 0, 0 ,0) int = 0 local currcam = workspace.CurrentCamera for _, v in pairs(game.Lighting.insertParts:GetChildren()) do button = Instance.new("TextButton", script.Parent.Parent.Parent.things) button.Size = size button.Position = pos pos = pos + UDim2.new(0.2, 0, 0, 0) if int == 5 then pos = pos + UDim2.new(0, 0, 0.04, 0) int = 0 end int = int + 1 button.Text = v.Name button.TextColor3 = Color3.new(1, 1, 1) button.Style = "RobloxButtonDefault" end button.MouseButton1Down:connect( function() local mouse local clone = game.Lighting.insertParts[button.Text]:Clone() clone.Parent = currcam clone.Transparency = 0.5 mouse.TargetFilter = clone dragging = true wait() while dragging do clone.Position = Vector3.new(math.floor(mouse.Hit.p.X), math.floor(mouse.Hit.p.Y), math.floor(mouse.Hit.p.Z)) wait() mouse.Button1Down:connect(function() dragging = false clone.Transparency = 0 clone.Parent = workspace end) end end ) |
|
|
| Report Abuse |
|
|
digpoe
|
  |
| Joined: 02 Nov 2008 |
| Total Posts: 9092 |
|
|
| 30 Jan 2013 10:50 AM |
No. You're not. Output: 16:53:08.034 - Players.Player1.PlayerGui.Interface.insertUI.Btns.blocks.Lo:32: attempt to index local 'mouse' (a nil value) 16:53:08.035 - Script "Players.Player1.PlayerGui.Interface.insertUI.Btns.blocks.Lo", Line 32 16:53:08.036 - stack end
That's where you added the 'local mouse' line. |
|
|
| Report Abuse |
|
|
digpoe
|
  |
| Joined: 02 Nov 2008 |
| Total Posts: 9092 |
|
|
| 30 Jan 2013 10:54 AM |
Aha! I fixed it!
Here's what seemed to fix it:
local button local size = UDim2.new(0.2, 0, 0.04, 0) local pos = UDim2.new(0, 0, 0 ,0) local num = 0 local currcam = workspace.CurrentCamera local clone script.Parent.MouseButton1Click:connect(--create buttons function() script.Parent.Parent.Parent.things:ClearAllChildren() for _, v in pairs(game.Lighting.insertParts:GetChildren()) do if num == 5 then pos = UDim2.new(0, 0, pos.Y.Scale + 0.04, 0) num = 0 end button = Instance.new("TextButton", script.Parent.Parent.Parent.things) button.Size = size button.Position = pos pos = pos + UDim2.new(0.2, 0, 0, 0) num = num + 1 button.Text = v.Name button.TextColor3 = Color3.new(1, 1, 1) button.Style = "RobloxButtonDefault" end button.MouseButton1Down:connect(--button pressed function() local mouse = game.Players.LocalPlayer:GetMouse() clone = game.Lighting.insertParts[button.Text]:Clone() wait() clone.Parent = currcam clone.Transparency = 0.5 mouse.TargetFilter = clone dragging = true wait() while dragging do --set position until... wait() pcall(function() clone.Position = Vector3.new(math.floor(mouse.Hit.p.X), math.floor(mouse.Hit.p.Y), math.floor(mouse.Hit.p.Z))end) wait() mouse.Button1Down:connect(--mouse down function() dragging = false clone.Transparency = 0 clone.Parent = workspace mouse.TargetFilter = nil wait() end ) end end ) end |
|
|
| Report Abuse |
|
|
digpoe
|
  |
| Joined: 02 Nov 2008 |
| Total Posts: 9092 |
|
|
| 30 Jan 2013 10:55 AM |
| oh, I forgot, the pcall() for the position was a test to see if the clone variable hadn't updated quickly enough. I suppose it isn't needed. |
|
|
| Report Abuse |
|
|
digpoe
|
  |
| Joined: 02 Nov 2008 |
| Total Posts: 9092 |
|
|
| 30 Jan 2013 11:46 AM |
| Ok, that's weird. My delete script can't set the parent of the part that I 'insert' to Lighting, but it does detect it. Also, if I 'insert' a new part that's the same then it can delete the original, but not the new one. Weird. |
|
|
| Report Abuse |
|
|