So I learned filtering enabled but I just touched the bare bones of it. I know how to use RemoteEvents and I tried to convert my script to filtering.
I tried to send the server where the player clicked but it wouldn't work. It would give me errors that didn't make sense. I'm not sure else how I could convert it. Can someone tell me how should I do it?
I don't need a full on script but rather an explanation.
I think I only need to show the Activation tool part of the script since that's where the raycasting happens. If you need me to show more you can leave down a comment and I'll show it.
If you like here is my script:
local function ToolActivate() if Ammo > 1 and Player.Character.Humanoid.Health > 1 and GunState.Firing then InputBeganEvent:Disconnect() repeat Settings.GunFire.Enabled = true Settings.GunLight.Enabled = true -- RemoteEvent:FireServer() -- gun values here Ammo = Ammo - 1 local ray = Ray.new(Tool.Handle.CFrame.p, (Mouse.Hit.p - Tool.Handle.CFrame.p).unit * 300) local part, position = game.Workspace:FindPartOnRay(ray, Player.Character, false, true) local beam = Instance.new("Part", workspace) --comestic beam.BrickColor = BrickColor.new("New Yeller") beam.FormFactor = "Custom" beam.Material = "Neon" --comestic beam.Transparency = 0.25 beam.Anchored = true --misc beam.Locked = true beam.CanCollide = false --preparation local distance = (Tool.Handle.CFrame.p - position).magnitude beam.Size = Vector3.new(0.3, 0.3, distance) --finialization beam.CFrame = CFrame.new(Tool.Handle.CFrame.p, position) * CFrame.new(0, 0, -distance / 2) game:GetService("Debris"):AddItem(beam, 0.06) Sounds.GunSound:Play() if part then --checking if ray hit a part local humanoid = part.Parent:FindFirstChild("Humanoid") if not humanoid then humanoid = part.Parent.Parent:FindFirstChild("Humanoid") end if humanoid then humanoid:TakeDamage(10) humanoid.WalkSpeed = humanoid.WalkSpeed / 2 end end wait(Settings.FireRate) Settings.GunFire.Enabled = false Settings.GunLight.Enabled = false until not GunState.Firing or Ammo == 0 end InputBeganEvent = UserInputService.InputBegan:Connect(InputBegan) if Ammo == 0 then ReloadGun() GunState.Firing = false end end --Settings is just a table that has editable stats in it. --GunState is just a table that is determining the state of the gun, e.g reloading, firing.
Edit: Here is my lines that are giving the error of "p is not a valid member of player". The error is on where it says local ray
local function FireServer(MouseHit, ToolHandleCFrame, Player, Damage) local ray = Ray.new(ToolHandleCFrame.p, (MouseHit.p - ToolHandleCFrame.p).unit * 300) local part, position = game.Workspace:FindPartOnRay(ray, Player.Character, false, true) --ToolHandleCFrame is just Tool.Handle.CFrame --MouseHit is just Mouse.Hit --Player is just the player who is firing the server --Damage is just the gun's damage.
Thank you for reading
From what I see, you are making a gun script. I'm going to assume you are using a Tool (hence the name "ToolActivated").
I would actually not use RemoteEvents at all. What I did fairly recently when making a sword tool is you take the entire script, and just put it into a normal Script object (not LocalScript). The server can still detect Tool.Activated events, and while it is not recommended to handle player animations through a server Script, it is neat, secure and from what I can tell, fast as well. The only downside is that you will have to get the player in some hacky way*. It's all hacky, but it works and I don't really see any strong reason why to not do it that way.
*
local player = nil repeat player = players:GetPlayerFromCharacter(tool.Parent) or tool.Parent.Parent wait() -- Empty wait()s should be avoided but I can't think of anything else until player and player.ClassName == "Player" local character = player.Character or player.CharacterAdded:Wait() local humanoid = character:WaitForChild("Humanoid")
P.S. I was just looking at your code, and only classes should begin with a capital letter. Normal variables should be camel case and constants should be all uppercase. Also, consider storing a pre-made beam part in ServerStorage or ReplicatedStorage, which you then can :Clone()
, as then you won't have to initialize a new one every time.