Why is my tower placement system breaking?

When you raycast, you give it the ORIGIN and you give it the DIRECTION. The origin is where the ray is meant to start, and then you give it a Vector3 Direction which is where you want the ray going.

You are currently using the origin as the Mouse.Hit, which is wrong because that would have to mean the ray starts in the target position they click.

This is where client comes into play, you can use the function I gave you above to get a normalized mouse position (X, Y, Z) and send that to the server when they want to place. (You can use the Camera.CFrame.Position as the origin point and then raycast in the direction) (Or if you want to keep it simple, you can send the server the Mouse.Hit.Position and then have the server Model:SetPrimaryPartCFrame(CFrame.new(Hit.X, Hit.Y, Hit.Z)) (You could also, if you want to keep the server raycasting for whatever reason, send the server the starting position (origin) and give it the direction for the server to initialize a ray)

Using the Camera.CFrame.Position as the origin worked! (I set the direction to face 100 studs down :laughing: 10 studs down just wasn’t enough) Thanks for the help!

1 Like

Glad to help. You can always come back to this thread in the future if you ever want to completely redo the system!

1 Like

I found something bad, and that bad thing is that I can place on tracks (Unless I’m facing from above)
Here’s how I’m currently raycasting:

local rayCast2 = game.Workspace:Raycast(camPos, Vector3.new(0, -100, 0), raycastParams)

I tried subtracting a value from mousePos and using that for the direction, but it errors when I position my camera up in the sky.

EDIT: Everything’s breaking all over again.

I think this is the time where you should just consider reworking it all. Getting the normalized mouse position on the client, sending coordinates to the server.

Using a Mouse.Move event to determine where to drag the model to. (On the client)

Alternatively, you can use this for the raycasting:

local Direction = (MouseHitPosition - CameraPosition).Unit * 300
local Ray = game.Workspace:Raycast(CameraPosition, Direction, RaycastParams)

Don’t forget, you are doing (what should be done on the client), on the server, so there are bound to be issues.

1 Like