I’m making a gun system (for PvE) and I want to visualize my bullets on everyone’s client, how can I do this? I’m unsure of where to get started, this is my current code:
local function fireBullet(mousePosition: Vector3)
local origin = firePoint.WorldPosition
local vectorDirection = (mousePosition - origin).Unit * Configuration.bulletRange
local raycastResult = Workspace:Raycast(origin, vectorDirection, raycastParams)
local intersection = raycastResult and raycastResult.Position or origin + vectorDirection
local distance = (origin - intersection).Magnitude
-- BULLET VISUALIZING PROCESS BELOW --
local cosmeticBullet = cosmeticBulletTemplate:Clone()
cosmeticBullet.Size = Vector3.new(0.1, 0.1, distance)
cosmeticBullet.CFrame = CFrame.lookAt(origin, intersection) * CFrame.new(0, 0, -distance/2)
cosmeticBullet.Parent = Workspace
task.delay(.25, function()
cosmeticBullet:Destroy()
end)
end
I was thinking when the raycast fires, I send a remoteEvent to all clients with the necessary info for the bullet’s position, size, etc. Then each client creates the bullet on their side using the info that was sent to it. Would this method work or do I have to do something else? Are there any bugs that could happen with this?