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

How to make this Filtering Enabled?

Asked by 4 years ago
Edited 4 years ago
originalAmmo = script.Parent.Ammo.Value
m = Instance.new("Message")

function computeDirection(vec)
    local lenSquared = vec.magnitude^2
    local invSqrt = 1 / math.sqrt(lenSquared)
    return Vector3.new(vec.x * invSqrt, vec.y * invSqrt, vec.z * invSqrt)
end



function updateAmmo()
    m.Text = " "
    --for i = 1,script.Parent.Ammo.Value do
    --  m.Text = m.Text .. "|"
    --end
    --for i = 1, (originalAmmo - script.Parent.Ammo.Value) do
    --  m.Text = m.Text .. " "
    --end
    m.Text = m.Text .. " " .. script.Parent.Ammo.Value.. "/10"
end


function fire(v)
    for i = 1,1 do
        script.Parent.Handle.Fire:play()
        script.Parent.Ammo.Value = script.Parent.Ammo.Value - 1
        updateAmmo()

        local dir = v - script.Parent["Handle"].Position
        dir = computeDirection(dir)

        local pos = script.Parent["Handle"].Position + (dir * 6)

        local p = Instance.new("Part")
        p.Name = "Projectile"
        p.CFrame = CFrame.new(pos, pos + dir)
        p.BrickColor = BrickColor.new(21)
        p.Reflectance = 0.1
        p.Velocity = (script.Parent.Parent["Head"].Position - v).unit * -150
        p.Size = Vector3.new(1, 0.4, 1)
        p.formFactor = 2

        local mesh = script.Parent.Mesh:clone()
        mesh.Parent = p

        local upforce = Instance.new("BodyForce")
        upforce.force = Vector3.new(0, p:GetMass() * 196, 0)
        upforce.Parent = p

        local creator = Instance.new("ObjectValue")
        creator.Name = "creator"
        creator.Value = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
        creator.Parent = p

        local s = script.Parent["ProjectileScript"]:Clone()
        s.Disabled = false
        s.Parent = p
        p.Parent = game.Workspace
        wait(0)
    end
end


function onActivated()
    if script.Parent.Enabled == true then
        script.Parent.Enabled = false
        if script.Parent.Ammo.Value > 0 then
            fire(script.Parent.Parent["Humanoid"].TargetPoint)
        else
            script.Parent.Enabled = false
            script.Parent.Handle.Reload:play()
            m.Text = "Reloading."
            for i =1,5 do
                wait(0.3)
                m.Text = m.Text .. "."
            end
            script.Parent.Ammo.Value = originalAmmo
            updateAmmo()
            script.Parent.Enabled = true
        end
        wait(0.1)
        script.Parent.Enabled = true
    end
end


function onEquipped()
    local p = game.Players:GetChildren()
    for i = 1,#p do
        if p[i].Character == script.Parent.Parent then
            m.Parent = p[i]
        end
    end
    updateAmmo()
end

function onUnequipped()
    m.Parent = nil
end


script.Parent.Activated:connect(onActivated)
script.Parent.Equipped:connect(onEquipped)
script.Parent.Unequipped:connect(onUnequipped)

1 answer

Log in to vote
2
Answered by 4 years ago
Edited 4 years ago

Well, we can not help you with the overall process of turning this code into a filtering enabled one as this is not a request site for you to utilize. We can only suggest you the tools and help you along the journey!

With that said, I will provide you a few Roblox API links that could really help you get into how to turn this code into a filtering enabled one.

Here is the explanation of what is Filtering Enabled and the properties it has, make sure to read the exceptions, very important so you do not lose time if you commit one!

https://developer.roblox.com/en-us/api-reference/property/Workspace/FilteringEnabled

As for the Filtering Enabled core communication tools you have Remote Events and Remote Functions, the link I will provide will explain in detail with examples all the possible communications you can do.

https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events

I also have an answer on a question on Scripting Helpers on where to put your scripts in case you attempt to script with Filtering Enabled.

https://scriptinghelpers.org/questions/55070/whats-the-best-place-to-store-local-scripts#53918

This is just a few of the links full with information that you can utilize to learn to code in Filtering Enabled and finally end up transforming your code to Filtering Enabled.

Good luck with your journey on transforming the code to Filtering Enabled, make sure to ask more questions if you get stuck with your attempt.

:)

1
if i would receive such answers like this one i would feel on this website like in heaven ErtyPL 129 — 4y
1
Hopefully it helps him research a bit on Filtering Enabled and learn from the experience though. iDarkGames 483 — 4y
Ad

Answer this question