I scripted my raycast gun to work with filteringenabled, and it partially works. When testing, the user sees the parts but does not take damage. The damage happens only on the client, not the server. Here are my scripts.
In ReplicatedFirst, I have a folder with a module script with this code:
local module = {}
function module.GunShooter(scarpt)
local tool = scarpt.Parent
local player = game.Players.LocalPlayer
local modulescript = require(game.ReplicatedStorage.WepHandler.UziHandler)
local mouse = player:GetMouse()
local user
local down = false
tool.Equipped:connect(function(mouse)
mouse.Icon = "rbxasset://textures\\GunCursor.png"
user = tool.Parent
mouse.Button1Down:connect(function()
down = true
--make and do a hit test along the ray
while down == true do
wait(0.0714285714)
game.Workspace.Shot:Play()
local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Barrel.CFrame.p).unit*300)
local hit, position = game.Workspace:FindPartOnRay(ray, user)
--do damage to any humanoids hit
local humanoid = hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid:TakeDamage(10)
end
local distance = (position - tool.Barrel.CFrame.p).magnitude
local rayPart = Instance.new("Part", user)
rayPart.Name = "RayPart"
rayPart.BrickColor = BrickColor.new("Bright red")
rayPart.Transparency = 0.5
rayPart.Anchored = true
rayPart.CanCollide = false
rayPart.TopSurface = Enum.SurfaceType.Smooth
rayPart.BottomSurface = Enum.SurfaceType.Smooth
rayPart.formFactor = Enum.FormFactor.Custom
rayPart.Size = Vector3.new(0.01, 0.01, distance)
rayPart.CFrame = CFrame.new(position, tool.Barrel.CFrame.p) * CFrame.new(0, 0, -distance/2)
--add it to debris so it disappears after 0.1 seconds
game.Debris:AddItem(rayPart, 0.1)
mouse.Button1Up:connect(function()
down = false
end)
end
end)
end)
end
return module
To call it, I have a local script in the tool that says this:
local modulescript = require(game.ReplicatedStorage.WepHandler.UziHandler)
modulescript.GunShooter(script)

1 comment
requie() in a localscript is the same as typing the code there. Why would it replicate...