How can you perform WorldRoot operations (e.g. GetPartsInBox(), Raycasting, those types of operations) on the client side without being forced to constantly communicate back and forth with the server? (obviously you must communicate with the server when you place a block, talking about when you move your mouse and the ghost block moves it needs to detect other blocks around it to ensure the block which can be rectangular does not phase into others) Thank you in advance.
#Client Side Placement System Troubles
1 messages · Page 1 of 1 (latest)
workspace:GetPartsInPart()
Ghost block would be on the client
then the client would tell the server to place at this spot
then just verify if thats valid
Oh, when I tried workspace:GetPartsInPart() didnt work
I don't know how to perform WorldRoot operations such as GetPartsInPart() on the client side. I always thought that could only be done on the server side
💀
there are some stuff that are only available through the server
isnt much tho
like Network ownership
only in server
and even some stuff thats only on clients
So, you can only detect parts that exist on the server side by settings those parts network ownership? I'm a little confused
Nevermind, my problem is accessing the WorldRoot on the client I believe
I'm an idiot. Was literally moving stuff on the wrong side...
?
when the server makes changes it "replicates" to the client
now the client can see them
Ok but what if I create a part on the client, like my ghost part. It wont exist in WorldRoot and the position wont be updated so shouldn't it not work with things like GetPartsInBox?
if the part isnt in workspace aka world root it cannot be detected by getparts in box thats true but also you cannot see the ghost part + the methods under workspace can be used everywhere
the client to server boundry doesnt affect it
like why do you need the server to know your doing this x thing like input stuff
Oh that sucks
The client side needs WorldRoot to offset parts. For example, if I put my mouse somewhere and the ghost part connected to my mouse intersects with a part it will move away from that part like a collision system
what are you talking about blud 💀
Do you not understand?
your not understanding things here
Yes, that's literally why I came here. I am asking if you do not understand what im trying to achieve
what do you want to achieve? a ghost part that only shows onthe client?
Yes
just clone the part on the client
With collisions
?
I don't want the part to be able to intersect other parts
Even if the mouse is not over the part that is intersecting
I could just use the normal of the part my mouse is over and do that, but what if my mouse is not actually over the intersecting part?
you mean you wanna make sure the part doest clip into other parts
I have to use GetPartsInBox() to determine that, which also means accessing WorldRoot which is my problem
world root is workspace
workspace is a global variable
or you can use game.Workspace
or game:GetService("Workspace")
yea
Ok so we have that
But now, I need to find intersecting parts (parts inside the ghost part)
Have you ever played Plane Crazy?
yea
local PartsInside = workspace:GetPartsInPart(Part)
Will that work for the ghost part which is technically not on the server side?
what?
once again you dont need the server side for it to work
I'm puzzled
I'm going to test that real quick
how 💀
I have 3 months experience in Studio, still learning
If that isnt already clear lol
@simple crane while wait(0.1) do for _, part in pairs(workspace:GetPartBoundsInBox()) do print(part.Name) end end
It's not printing anything whatsoever
wait..
I'm an actual dumbass LOL
Ok fixed it still not printing anything
where part 🤨
I know that was what I forgot
is the code even running?
Yes
your using GetPartBoundsInBox not GetPartsInPart
you need a cframe and size for GetPartBoundsInBox to work
Oh my bad, ill try the other
Oh wait
I'll try the box one, should be better on performance
Hm, still no print. I'm moving a part inside of it and nothing happens
is that in a localscript
Yes
local scripts doesnt work in workspace
/:
wait
You mean the LocalScript cannot exist within the workspace?
i mean local script wont run in workspace
?
Do I have to do the calculations for intersecting parts myself (I already made it)
?
local cframe = part.CFrame
local halfSize = part.Size / 2
local corners = {
cframe:PointToWorldSpace(halfSize),
cframe:PointToWorldSpace(-halfSize),
cframe:PointToWorldSpace(Vector3.new(halfSize.X, halfSize.Y, -halfSize.Z)),
cframe:PointToWorldSpace(Vector3.new(halfSize.X, -halfSize.Y, halfSize.Z)),
cframe:PointToWorldSpace(Vector3.new(-halfSize.X, halfSize.Y, halfSize.Z)),
cframe:PointToWorldSpace(Vector3.new(-halfSize.X, -halfSize.Y, -halfSize.Z)),
cframe:PointToWorldSpace(Vector3.new(halfSize.X, -halfSize.Y, -halfSize.Z)),
cframe:PointToWorldSpace(Vector3.new(-halfSize.X, halfSize.Y, halfSize.Z))
}
local min = Vector3.new(math.huge, math.huge, math.huge)
local max = Vector3.new(-math.huge, -math.huge, -math.huge)
for _, corner in pairs(corners) do
min = Vector3.new(
math.min(min.X, corner.X),
math.min(min.Y, corner.Y),
math.min(min.Z, corner.Z)
)
max = Vector3.new(
math.max(max.X, corner.X),
math.max(max.Y, corner.Y),
math.max(max.Z, corner.Z)
)
end
return Region3.new(min, max)
end
local function DoAABBIntersect(part1: Instance, part2: Instance)
local AABB1, AABB2
AABB1 = part1.AABB or CalculateAABB(part1)
AABB2 = part2.AABB or CalculateAABB(part2)
return not (
AABB1.Max.X < AABB2.Min.X or AABB1.Min.X > AABB2.Max.X or
AABB1.Max.Y < AABB2.Min.Y or AABB1.Min.Y > AABB2.Max.Y or
AABB1.Max.Z < AABB2.Min.Z or AABB1.Min.Z > AABB2.Max.Z
)
end```
workspace:GetPartBoundsInBox gets intesecting parts
thats aabb
Cant use that in a LocalScript
My game is going to consist of rectangular objects that can only be rotated in 90 degree increments so yes
I only need the AABB bounding box
alr then it should work
I already thought of this, but imagine having to run it over potentially thousands of blocks
Region3 is deprecated btw
It is?
yea
Nothing says deprecated
https://create.roblox.com/docs/reference/engine/datatypes/Region3
I'm not using that
Region3 itself does not say deprecated
what are you gonna use it for
GetPartBoundsInBox works fine for me on the client
Could you show me? I thought you said and I even tested that workspace could not be accessed on a LocalScript
while task.wait() do
print(workspace:GetPartBoundsInBox(workspace.Part1.CFrame, workspace.Part1.Size))
end
I see why its working
It's because your parts already exist in the workspace
I'm trying to summon a new part on the client side only
local Part = script:WaitForChild("Part1"):Clone()
Part.Anchored = true
Part.Parent = workspace
while task.wait() do
print(workspace:GetPartBoundsInBox(Part.CFrame, Part.Size))
end
Interesting, still works if you move stuff around?
yea
Huh! So you are moving it on the client or server side while its running?
client ofc
Alright well, thanks for the help. I appreciate it and will try tomorrow. I have to head out soon so bye