Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Filtering Enabled in gun script not working?

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.

1 comment

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

1 answer

✓ Accepted answer

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)

1 comment

0

I changed the UserInputService to an Activated event to make it work

This discussion is preserved as it was. New answers, comments, and votes are closed.