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

Filtering Enabled in gun script not working?

Asked by 5 years ago

With this script i'm just trying to make a projectile spawn and move. It worked before I tried to add FE but just doesn't work at all when I attempted to implement it. I'm still pretty iffy on FE so I have no idea what to do next.

Local Script

local function fds()
    script.Parent.Equipped:connect(function(mouse)
    mouse.Button1Down:connect(function()
    local bullet = game:GetService("ReplicatedStorage").Bullet:Clone()
    bullet.CFrame = script.Parent.muzzle.CFrame
    bullet.Parent = workspace
    bullet.Velocity = bullet.CFrame.lookVector  * 600
        end)
    end)
end

game:GetService("ReplicatedStorage").GunShoot.OnClientEvent:Connect(fds)

Script

game:GetService("ReplicatedStorage").GunShoot:FireClient()

I am just getting back into script after a couple months so I forgot a bunch of stuff.

0
Why are you creating a bullet in the client? Do it in the server or else it won't be seen by other players, and can you show us the whole server script. Last of all, you should try raycasting. I find raycasting very easy from this wiki page:https://developer.roblox.com/articles/Making-a-ray-casting-laser-gun-in-Roblox MahadTheIronSword 98 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

You shouldn't connect a function to Equipped each time you receive a FireClient. Same for Equipped, you shouldn't connect a new function to Button1Down every time you equip the tool.

Instead, you should handle the decision of the gun firing on the server.

-- Client below

local isEquipped = false;
local gunTool = game.Players.LocalPlayer.Backpack:WaitForChild'gunTool'
local uis = game:GetService'UserInputService'

gunTool.Equipped:Connect(function()
    isEquipped = not isEquipped -- turns false if true, turns true if false
end)

uis.InputBegan:Connect(function(input, typing)
    if not typing then 
        if input == Enum.UserInputType.MouseButton1 then
            game.ReplicatedStorage.GunShoot:FireServer() -- server will handle
        end
    end
end)

-- Server below

game.ReplicatedStorage.GunShoot.OnServerEvent:connect(function(p)
    local bullet = game:GetService("ReplicatedStorage").Bullet:Clone()
    bullet.CFrame = p.Character.gunTool.muzzle.CFrame
    bullet.Parent = workspace
    bullet.Velocity = bullet.CFrame.lookVector  * 600
end)
0
I changed the UserInputService to an Activated event to make it work poopstermaniac 1 — 5y
Ad

Answer this question