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
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Place object help.

Previous Thread :: Next Thread 
leomesa is not online. 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 is not online. leomesa
Joined: 11 Apr 2014
Total Posts: 1029
03 Aug 2016 12:20 AM
bump
Report Abuse
leomesa is not online. leomesa
Joined: 11 Apr 2014
Total Posts: 1029
03 Aug 2016 12:25 AM
bump ##
Report Abuse
leomesa is not online. 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 is not online. leomesa
Joined: 11 Apr 2014
Total Posts: 1029
03 Aug 2016 10:16 AM
Bump
Report Abuse
C0mmando323 is not online. C0mmando323
Joined: 15 Dec 2012
Total Posts: 394
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
AggressiveCatch is not online. AggressiveCatch
Joined: 17 Jul 2011
Total Posts: 5840
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
C0mmando323 is not online. C0mmando323
Joined: 15 Dec 2012
Total Posts: 394
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 is not online. leomesa
Joined: 11 Apr 2014
Total Posts: 1029
03 Aug 2016 10:29 AM
Alright I'll try out your suggestions.
Report Abuse
AggressiveCatch is not online. AggressiveCatch
Joined: 17 Jul 2011
Total Posts: 5840
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
C0mmando323 is not online. C0mmando323
Joined: 15 Dec 2012
Total Posts: 394
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 is not online. 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
C0mmando323 is not online. C0mmando323
Joined: 15 Dec 2012
Total Posts: 394
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 is not online. 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 is not online. 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
C0mmando323 is not online. C0mmando323
Joined: 15 Dec 2012
Total Posts: 394
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 is not online. leomesa
Joined: 11 Apr 2014
Total Posts: 1029
03 Aug 2016 10:51 AM
I could use some help :|
Report Abuse
C0mmando323 is not online. C0mmando323
Joined: 15 Dec 2012
Total Posts: 394
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 is not online. 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 is not online. leomesa
Joined: 11 Apr 2014
Total Posts: 1029
03 Aug 2016 11:01 AM
bump
Report Abuse
C0mmando323 is not online. C0mmando323
Joined: 15 Dec 2012
Total Posts: 394
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 is not online. 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 is not online. 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
AggressiveCatch is not online. AggressiveCatch
Joined: 17 Jul 2011
Total Posts: 5840
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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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