3d building system fails to function as intended, is there a reason why?
Here is my LOCAL script:
01 | local Players = game:GetService( "Players" ) |
02 | local Camera = workspace.CurrentCamera |
03 | local UIS = game:GetService( "UserInputService" ) |
04 | local rs = game:GetService( "RunService" ).RenderStepped |
05 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
06 | local Ghost = ReplicatedStorage.ItemIndicator |
08 | local Item = "Plastic Test Brick" |
09 | Ghost.Parent = workspace |
16 | function GetMousePoint(X, Y) |
18 | local RayMag 1 = Camera:ScreenPointToRay(X, Y) |
19 | local NewRay = Ray.new(RayMag 1. Origin, RayMag 1. Direction * 1000 ) |
20 | local Target, Position = workspace:FindPartOnRayWithWhitelist(NewRay, workspace.Parts:GetChildren()) |
24 | function snap(num) return math.floor(num/ 4 + 0.5 )* 4 end |
30 | Ghost.Parent = workspace |
31 | mousePos = GetMousePoint(UIS:GetMouseLocation().X, UIS:GetMouseLocation().Y) |
32 | gridPos = Vector 3. new(snap(mousePos.X), snap(mousePos.Y), snap(mousePos.Z)) |
33 | Ghost.CFrame = CFrame.new(gridPos) |
36 | local region = Region 3. new(Ghost.Position+Ghost.Size/ 2.1 , Ghost.Position-Ghost.Size/ 2.1 ) |
38 | local parts = workspace:FindPartsInRegion 3 (region, Ghost) |
42 | Ghost.Color = Color 3. fromRGB( 255 , 89 , 89 ) |
46 | Ghost.Color = Color 3. fromRGB( 123 , 255 , 93 ) |
55 | UIS.InputBegan:Connect( function (input) |
57 | if input.UserInputType = = Enum.InputType.MouseButton 1 then |
60 | ReplicatedStorage.PlacePart:FireServer(Ghost.Position, Item) |
Here is my SERVER script, but I don't think the problem is it:
01 | local rs = game:GetService( "ReplicatedStorage" ) |
02 | local ss = game:GetService( "ServerStorage" ) |
04 | rs.PlacePart.OnServerEvent:Connect( function (player, position, partType) |
05 | local part = ss:WaitForChild(partType, 5 ):Clone() |
07 | part.Position = position |
08 | part.Parent = workspace |
10 | error ( "Part Failed to Load" ) |
P.S. There are no errors in the output.
The problem I have is that when using the grid movement, these three things happen:
- Parts fail to go to the right area
- Ghost part fails to turn red when region3 detects a problem
- Bricks do not get placed
Here's a gif if it makes it easier: https://gyazo.com/cdb07c9616926c4bdd99ce4a5eca1d51
I've tried countless times to make this work, but I can't seem to get it right, thank you if you can solve it!