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

How would I make this script filtering enabled?

Asked by 5 years ago
Edited 4 years ago

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

0
I dont think you activated the function bro xd NarwhalAndMe 141 — 5y
0
I'm surprised that you have 85 reputation with this type of question. RBLXNogin 187 — 5y
0
I activated the function lol and I am new to this stuff, I’ve been scripting my game before the filter update game and it broke my scripts. 123nabilben123 499 — 5y
0
the "p is not a valid member of player" is caused by you trying to get a property called "p" from a player object. Seeing as in the line where it errors you are trying to get p from ToolHandleCFrame and HouseHit, it means one of those is actually the player. Also, I see that all those are parameters, so perhaps try checking if you are passing them to the RemoteEvent:FireServer() function in the RiskoZoSlovenska 378 — 4y
View all comments (2 more)
0
same order RiskoZoSlovenska 378 — 4y
0
It fully worked! It is just only placing the raycasting beam at a werid angle. 123nabilben123 499 — 4y

1 answer

Log in to vote
1
Answered by 5 years ago

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.

0
Thanks for the feedback! I'll try this and see if it works! 123nabilben123 499 — 5y
1
One thing though, a LocalScript can only take input from UserInputService, What should I do to make it compatible? 123nabilben123 499 — 5y
1
Well, this is where it gets a bit tricky. If you only need the Tool.Activated event, the Server can do that. But since you are asking about UserInputService, I assume you don't. What I would do in this case is make a LocalScript and a RemoteEvent alongside the server Script, and have the LocalScript fire input to the server Script whenever it gets some input. I trust you know how to use Remotes. RiskoZoSlovenska 378 — 5y
0
I like your idea but when I call FireServer() do I give like the gun’s position, mouse.Hit etc? I think I have to do that in order to cast the ray. 123nabilben123 499 — 5y
View all comments (6 more)
0
Sorry if the mass amount of questions is bothering you 123nabilben123 499 — 5y
1
yes. whatever the user input gives you that you need, send it through the RemoteEvent. RiskoZoSlovenska 378 — 4y
0
the output gave me errors saying "p is not a valid member of Player" I assume it's just my script being weird. I'll edit my question to show what I typed. Also I accepted your answer cause it somewhat worked 123nabilben123 499 — 4y
1
Thanks :D if you need any more help, just ask! RiskoZoSlovenska 378 — 4y
0
Um the output gave me "p is not a valid member of Player" It happened on the first line (see my question post I edited it) I think it's just me messing up but i do not realize the error.. 123nabilben123 499 — 4y
1
i posted a comment in your question... try that. RiskoZoSlovenska 378 — 4y
Ad

Answer this question