Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why isn't my ray casting for other players?

Asked by 5 years ago

Here is my script. As the client trying to cast the ray you can see it, but other clients cannot see the ray.

local function fire()   
    -- Checks
    if canShoot:InvokeServer() then
        --Initialize
        if recoilTrack then
            recoilTrack:Play()
        end
        flashGui.Enabled = true

        -- 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)

        -- Hit Detection
        if touch then
            hitRemote:FireServer(touch)
        end
        shootRemote:FireServer()

        -- Trace
        if allowTracing.Value then
            -- Create
            local trace = Instance.new("Part")
            trace.Anchored = trace
            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)

            wait(0.1)

            flashGui.Enabled = false
        end
    end
end

2 answers

Log in to vote
2
Answered by
amanda 1059 Moderation Voter
5 years ago

With FilteringEnabled, objects created on the client do not automatically replicate to the server, as to mitigate exploits.

You can still do the raycasting on the client, however for the part to be visible to everyone you must create it on the server.

I recommend firing a RemoteEvent to the Server containing all information needed to construct the part that is determined from the Ray. For example, start position, end position, and length.

Ad
Log in to vote
0
Answered by 5 years ago

I would recommend learning how to script instead of copy and pasting code, because that doesn't get you anywhere. Try going to wiki.roblox.com

Answer this question