I was able to create a bullet trail on my client, but I want other players to be able to see it. To do this I am creating the part on the server, as you see below.
local function trace() -- Create local trace = Instance.new("Part") trace.Anchored = true trace.CanCollide = false trace.Transparency = 0.5 trace.BrickColor = BrickColor.new("White") trace.Material = Enum.Material.SmoothPlastic -- Calculate local distance = (hole.CFrame.p - position).magnitude trace.Size = Vector3.new(0, 0, distance) trace.CFrame = CFrame.new(hole.CFrame.p, position) *CFrame.new (0, 0, -distance/2) trace.Parent = workspace -- Clean-up game:GetService("Debris"):AddItem(trace, 0.1)
However, I am not sure how I can get the position on the ray from the localscript below to the server so I can use it for creation of the bullet trail.
-- Cast Ray local ray = Ray.new(hole.CFrame.p, (mouse.hit.p - hole.CFrame.p).unit * range.Value) local touch, position = workspace:FindPartOnRay(ray, player.Character, false, true)
Hello.
You can send all the data to the server using RemoteEvents. RemoteEvents provide the ability to send data from the client to the server in an efficient manner.
-- Server local function trace(player,position) -- Code here end remoteEvent.OnServerEvent:Connect(trace) -- define remoteEvent as a RemoteEvent placed in workspace or replicated storage.
-- Client local ray = Ray.new(hole.CFrame.p, (mouse.hit.p - hole.CFrame.p).unit * range.Value) local touch, position = workspace:FindPartOnRay(ray, player.Character, false, true) remoteEvent:FireServer(position) -- same here
The arguments provided in the trace function is the local player that came from the FireServer, as well as the position received from the client.
Please note that there will be a tiny delay in this code. That's called latency, which is the delay of sending information from a client to the server, and this can change at different times, but it's usually never more than half a second.
Lastly, as incapaz said, you did make a variable named trace
after naming the function trace
. Make sure that everything is named differently so the script doesn't get confused as to what is what.
Hope this helps, make sure to accept my answer if it helped. Have a good day! :)
This is on lines 1 and 3. You named your function trace
, but then made a variable named trace
. Rename your function or your variable.