leomesa
|
  |
| Joined: 11 Apr 2014 |
| Total Posts: 1029 |
|
|
| 03 Aug 2016 12:14 AM |
How can I go by cloning an object on the face of another object. Sorta like in how in Minecraft your able to place blocks on the face of another. What am doing doesn't seem to be going exactly how I planned.
These aren't the full scripts there just the chunk where everything goes:
Local Script:
mouse.Button2Down:connect(function() if mouse.Target then PlaceBlock:FireServer(mouse.Target, mouse.Hit.p) end end)
ServerScript:
PlaceBlock.OnServerEvent:connect(function(plr, target, hit) local UIBar = plr:WaitForChild("PlayerGui").UIBAR.MainFrame.HotbarSystemSection if UIBar.Slot1.Slot.PlaceUse.Value == true then local object = UIBar.Slot1.Slot.ItemObj.Value:Clone() object.Parent = game.Workspace.PlacedBlocks local ray = Ray.new(object.CFrame.p,hit) local part, hit, surfaceVector = workspace:FindPartOnRay(ray) surfaceVector = surfaceVector * part.Size.X/2 object.CFrame = part.CFrame * CFrame.new(surfaceVector) else print("UnPlaceAble") end end)
Here is the code so you can see it better:
local object = UIBar.Slot1.Slot.ItemObj.Value:Clone() object.Parent = game.Workspace.PlacedBlocks local ray = Ray.new(object.CFrame.p,hit) local part, hit, surfaceVector = workspace:FindPartOnRay(ray) surfaceVector = surfaceVector * part.Size.X/2 object.CFrame = part.CFrame * CFrame.new(surfaceVector)
|
|
|
| Report Abuse |
|
|
leomesa
|
  |
| Joined: 11 Apr 2014 |
| Total Posts: 1029 |
|
| |
|
leomesa
|
  |
| Joined: 11 Apr 2014 |
| Total Posts: 1029 |
|
| |
|
leomesa
|
  |
| Joined: 11 Apr 2014 |
| Total Posts: 1029 |
|
|
| 03 Aug 2016 12:28 AM |
| bump ### I'ma go to bed hopefully there's a solution in the morning! |
|
|
| Report Abuse |
|
|
leomesa
|
  |
| Joined: 11 Apr 2014 |
| Total Posts: 1029 |
|
| |
|
|
| 03 Aug 2016 10:19 AM |
You're missing an argument when you fire the server:
(LOCAL SCRIPT) mouse.Button2Down:connect(function() if mouse.Target then PlaceBlock:FireServer(mouse.Target, mouse.Hit.p, mouse.Hit) --I'm assuming you wanted mouse.Hit end end)
Hopefully this helps, I have a notifications chrome plugin so just reply on this thread if it doesn't work still and I'll try to get back to you.
Lead Developer of Theatric Entertainment |
|
|
| Report Abuse |
|
|
|
| 03 Aug 2016 10:21 AM |
"local ray = Ray.new(object.CFrame.p,hit)"
that part doesn't make sense
why are you sending a ray from the cframe of the just cloned object? the first argument should be changed |
|
|
| Report Abuse |
|
|
|
| 03 Aug 2016 10:23 AM |
I don't think it really matters if the ray is casted from the Cloned object or the actual object seeing as they are the same object just different instances.
Lead Developer of Theatric Entertainment |
|
|
| Report Abuse |
|
|
leomesa
|
  |
| Joined: 11 Apr 2014 |
| Total Posts: 1029 |
|
|
| 03 Aug 2016 10:29 AM |
| Alright I'll try out your suggestions. |
|
|
| Report Abuse |
|
|
|
| 03 Aug 2016 10:31 AM |
"I don't think it really matters if the ray is casted from the Cloned object or the actual object seeing as they are the same object just different instances."
no, it should be casted from the camera to the mouse's position because he is trying to get the surface of the part that was clicked |
|
|
| Report Abuse |
|
|
|
| 03 Aug 2016 10:33 AM |
Oh, I misunderstood, I understand what you were saying now, my bad. Sorry.
Lead Developer of Theatric Entertainment |
|
|
| Report Abuse |
|
|
leomesa
|
  |
| Joined: 11 Apr 2014 |
| Total Posts: 1029 |
|
|
| 03 Aug 2016 10:33 AM |
All i got was this: ServerScriptService.GameEventsManager:67: bad argument #2 to 'new' (Vector3 expected, got CFrame) |
|
|
| Report Abuse |
|
|
|
| 03 Aug 2016 10:36 AM |
Try putting this in on that line, I don't know what line it is (I know it's 67, I don't know what's on that line), but put in: Your_CFrame_Value_Thats_On_That_Line.p This will return the Vector3 equivalent of your CFrame (meaning this method returns the CFrame without the rotation from your CFrame)
Lead Developer of Theatric Entertainment |
|
|
| Report Abuse |
|
|
leomesa
|
  |
| Joined: 11 Apr 2014 |
| Total Posts: 1029 |
|
|
| 03 Aug 2016 10:40 AM |
| Ah, this is line 67 btw local ray = Ray.new(object.CFrame.p,hit) and also how can I do Aggressive's method as I have never worked with rays that much before? |
|
|
| Report Abuse |
|
|
leomesa
|
  |
| Joined: 11 Apr 2014 |
| Total Posts: 1029 |
|
|
| 03 Aug 2016 10:48 AM |
| So wait I just get the camera and hit.p on line 67? |
|
|
| Report Abuse |
|
|
|
| 03 Aug 2016 10:51 AM |
Oh, your problem is you're using a Vector3 and it's expecting a Unit. Add in Vector3.new().Unit
Lead Developer of Theatric Entertainment |
|
|
| Report Abuse |
|
|
leomesa
|
  |
| Joined: 11 Apr 2014 |
| Total Posts: 1029 |
|
| |
|
|
| 03 Aug 2016 10:53 AM |
Well, a Unit is a Vector3 with a direction. To get the direction between two objects, use Vector3.new(PartA.Position-PartB.Position).Unit
Lead Developer of Theatric Entertainment |
|
|
| Report Abuse |
|
|
leomesa
|
  |
| Joined: 11 Apr 2014 |
| Total Posts: 1029 |
|
|
| 03 Aug 2016 10:55 AM |
| Alright but what im not understanding is how am I supposed to get the camera and the mouses position if camera only has CFrame? |
|
|
| Report Abuse |
|
|
leomesa
|
  |
| Joined: 11 Apr 2014 |
| Total Posts: 1029 |
|
| |
|
|
| 03 Aug 2016 11:01 AM |
Camera Position: workspace.CurrentCamera.CFrame.p
Mouse Position: game.Players.LocalPlayer:GetMouse().Hit.p
Lead Developer of Theatric Entertainment |
|
|
| Report Abuse |
|
|
leomesa
|
  |
| Joined: 11 Apr 2014 |
| Total Posts: 1029 |
|
|
| 03 Aug 2016 11:05 AM |
| Oh I didn't notice CFrame had a position. My bad. Well thanks im'a go try that out now. |
|
|
| Report Abuse |
|
|
leomesa
|
  |
| Joined: 11 Apr 2014 |
| Total Posts: 1029 |
|
|
| 03 Aug 2016 11:10 AM |
Looks like the position might be working but there is something else wrong with my script that comes with an error saying ServerScriptService.GameEventsManager:69: attempt to index local 'part' (a nil value)
local object = UIBar.Slot1.Slot.ItemObj.Value:Clone() object.Parent = game.Workspace.PlacedBlocks local ray = Ray.new(game.Workspace.CurrentCamera.CFrame.p, hitp) local part, hit, surfaceVector = workspace:FindPartOnRay(ray) 69-- surfaceVector = surfaceVector * part.Size.X/2 object.CFrame = part.CFrame * CFrame.new(surfaceVector) |
|
|
| Report Abuse |
|
|
|
| 03 Aug 2016 11:11 AM |
local part, hit, surfaceVector = workspace:FindPartOnRay(ray) if not part then return end
because if you clicked nothing there would be no part |
|
|
| Report Abuse |
|
|
leomesa
|
  |
| Joined: 11 Apr 2014 |
| Total Posts: 1029 |
|
|
| 03 Aug 2016 11:14 AM |
| Oh thanks! Just one problem whenever I place a block it just comes straight to me head not the surface of another block? |
|
|
| Report Abuse |
|
|