So I turned on FilteringEnabled in my game, it breaks the gun I've been tweaking slowly. I've created a remote event, and gave it two different attempts neither work. This is a Script, there is a LocalScript, inside the tool playing an animation because I'm lazy and don't want to CFrame arms and welds and more part etc. Besides that, how can I work this with FilteringEnabled, and turning it off isn't an option even though it works fine without it.
What I want the RemoteEvent to do is either, find the mouse position or, TargetPoint, if neither of these can be done, how can I do this, making it raycast out of the part "Exit"?
Try 1:
local Tool = script.Parent local vExit = Tool:WaitForChild("Exit") local Config = Tool:WaitForChild("Configuration") local PointEvent = Instance.new("RemoteEvent") PointEvent.Parent = script.Parent PointEvent.Name = "PointEvent" ------------------------------------------------ function Equip() Wielder = Tool.Parent Player = Wielder.Name Fire = Tool.Handle:WaitForChild("Fire") Pump = Tool.Handle:WaitForChild("Pump") end ------------------------------------------------ function Unequip() if Fire then Fire:Stop() end if Pump then Pump:Stop() end end ------------------------------------------ function Reload() Tool.Enabled = false for i = 1, 7 do Config.Ammo.Value = Config.Ammo.Value + 1 Pump:Play() wait(Fire.TimeLength) end Tool.Enabled = true end ----------------------------------------- I'M THE PROBLEM function Fire() PointEvent:FireServer(Wielder.Humanoid.TargetPoint) PointEvent.OnServerEvent:connect(function(player, target) TARGET = (target) end) if Tool.Enabled == false then return end if Config.Ammo.Value <= 0 then Reload() return end if Fire then Fire:Play() end Config.Ammo.Value = Config.Ammo.Value - 1 Tool.Enabled = false for i = 1, math.random(7,10) do --number of bullets coming out local ray = Ray.new(Tool.Exit.Position, ((TARGET --[[Here, I start the bullet but I can't be found in FilteringEnabled]] - Vector3.new(math.random(-0.25, 1), math.random(-1,2), math.random(-0.25, 1)) - Tool.Exit.Position)).unit * 45) local part, position = workspace:FindPartOnRay(ray, game.Workspace:FindFirstChild(Player), false, true) local beam = Instance.new("Part", workspace) beam.BrickColor = BrickColor.new("Medium stone grey") beam.FormFactor = "Custom" beam.Material = "Plastic" beam.Transparency = 0.915 beam.Anchored = true beam.Locked = true beam.CanCollide = false local distance = (Tool.Exit.CFrame.p - position).magnitude beam.Size = Vector3.new(0.05, 0.05, distance) beam.CFrame = CFrame.new(Tool.Exit.CFrame.p, position) * CFrame.new(Tool.Exit.Position,Tool.Exit.CFrame.p, -distance / 2) game:GetService("Debris"):AddItem(beam, 0.1) if part then local humanoid = part.Parent:FindFirstChild("Humanoid") if not humanoid then humanoid = part.Parent.Parent:FindFirstChild("Humanoid") end if humanoid then humanoid:TakeDamage(math.random(5.5,7)) end end end wait(.565) Tool.Enabled = true end --------------------------------------- Tool.Equipped:connect(Equip) Tool.Unequipped:connect(Unequip) Tool.Activated:connect(Fire)
Try 2:
local Tool = script.Parent local vExit = Tool:WaitForChild("Exit") local Config = Tool:WaitForChild("Configuration") local PointEvent = Instance.new("RemoteEvent") PointEvent.Parent = script.Parent PointEvent.Name = "PointEvent" ------------------------------------------------ function Equip() Wielder = Tool.Parent Player = Wielder.Name Fire = Tool.Handle:WaitForChild("Fire") Pump = Tool.Handle:WaitForChild("Pump") while true do PointEvent:FireServer(mouse.Hit.p) PointEvent.OnServerEvent:connect(function(player, target) TARGET = (target) print(target) end) wait() end end ------------------------------------------------ function Unequip() if Fire then Fire:Stop() end if Pump then Pump:Stop() end end ------------------------------------------ function Reload() Tool.Enabled = false for i = 1, 7 do Config.Ammo.Value = Config.Ammo.Value + 1 Pump:Play() wait(Fire.TimeLength - 0.045) end Tool.Enabled = true end ----------------------------------------- I'M THE PROBLEM function Fire() if Tool.Enabled == false then return end if Config.Ammo.Value <= 0 then Reload() return end if Fire then Fire:Play() end Config.Ammo.Value = Config.Ammo.Value - 1 Tool.Enabled = false for i = 1, math.random(7,10) do --number of bullets coming out local ray = Ray.new(Tool.Exit.Position, ((TARGET --[[Here, I start the bullet but I can't be found in FilteringEnabled]] - Vector3.new(math.random(-0.25, 1), math.random(-1,2), math.random(-0.25, 1)) - Tool.Exit.Position)).unit * 45) local part, position = workspace:FindPartOnRay(ray, game.Workspace:FindFirstChild(Player), false, true) local beam = Instance.new("Part", workspace) beam.BrickColor = BrickColor.new("Medium stone grey") beam.FormFactor = "Custom" beam.Material = "Plastic" beam.Transparency = 0.935 beam.Anchored = true beam.Locked = true beam.CanCollide = false local distance = (Tool.Exit.CFrame.p - position).magnitude beam.Size = Vector3.new(0.05, 0.05, distance) beam.CFrame = CFrame.new(Tool.Exit.CFrame.p, position) * CFrame.new(Tool.Exit.Position,Tool.Exit.CFrame.p, -distance / 2) game:GetService("Debris"):AddItem(beam, 0.1) if part then local humanoid = part.Parent:FindFirstChild("Humanoid") if not humanoid then humanoid = part.Parent.Parent:FindFirstChild("Humanoid") end if humanoid then humanoid:TakeDamage(math.random(5.5,7)) end end end wait(.565) Tool.Enabled = true end --------------------------------------- Tool.Equipped:connect(Equip) Tool.Unequipped:connect(Unequip) Tool.Activated:connect(Fire)
Also, this is my first time using RemoteEvents.