This question has been bugging me for a couple days now. How would I be able to convert this tool to filtering enabled? In filtering enabled it just doesn't do anything. It has two scripts, both server scripts, and I've tried experimenting but it just never goes anywhere. I'm pretty new to scripting. What in specific would I have to do?

maxDistance = 300
damage = 10
ammoLimit = script.Parent.HasLimitedAmmo

ammo = script.Parent.Charge
firing = script.Parent.Firing

Tool = script.Parent
sound = Tool.Handle.FireSound

TorsoConnection = nil
ArmConnection = nil

target = nil

beam = Instance.new("Part")
beam.Anchored = true
beam.CanCollide = false
beam.BrickColor = BrickColor.new("Magenta")
beam.formFactor = "Symmetric"
beam.TopSurface = 0
beam.BottomSurface = 0

local mesh = Instance.new("CylinderMesh")
mesh.Scale = Vector3.new(0.25,1,0.25)
mesh.Parent = beam

effect = nil

function getHumanoid(model)
	function excluded(name)
		local excluded = {}
		for i,child in pairs(excluded) do
			if string.lower(child) == string.lower(name) then
				return true
			end
		end
		return false
	end
	for i,child in pairs(model:getChildren()) do
		if child.className == "Humanoid" and not excluded(child.Name) then
			return child
		end
	end
end

touchEnabled = true
function onTouch(hit)
	if hit.Parent == Tool or hit.Parent == Tool.Parent or not touchEnabled then return end
	local human = getHumanoid(hit.Parent)
	if human ~= nil then
		if target ~= nil then
			if hit.Parent == target.Parent then
				return
			end
		end
		touchEnabled = false
		tagHumanoid(human)
		human:takeDamage(damage)
		wait(0.1)
		untagHumanoid(human)
		touchEnabled = true
	end
end
beam.Touched:connect(onTouch)

function attack(human)
	tagHumanoid(human)
	human:takeDamage(damage)
	wait(0.1)
	untagHumanoid(human)
end

function tagHumanoid(humanoid)
	local tag = Instance.new("ObjectValue")
	tag.Name = "creator"
	tag.Value = game.Players.LocalPlayer
	if tag ~= nil then
		local new_tag = tag:clone()
		new_tag.Parent = humanoid
	end
end


function untagHumanoid(humanoid)
	if humanoid ~= nil then
		local tag = humanoid:findFirstChild("creator")
		if tag ~= nil then
			tag.Parent = nil
		end
	end
end


function clearEffectScripts()
	for i,child in pairs(beam:getChildren()) do
		if child.Name == "LaserEffectScript" then
			child:remove()
		end
	end
end


down = false
function onButton1Down(mouse)
	if ammoLimit.Value then
		if ammo.Value <= 0 then
			return
		end
	end
	down = true
	firing.Value = true
	target = mouse.Target
	clearEffectScripts()
	effect = script.Parent.LaserEffectScript:clone()
	effect.Disabled = false
	effect.Parent = beam
	local handlepos = (Tool.Handle.CFrame * CFrame.new(0,-0.5,-2)).p
	local dist = math.abs((mouse.Hit.p - handlepos).magnitude)
	if dist <= maxDistance then
		sound:play()
		beam.Size = Vector3.new(1,math.ceil(dist),1)
		beam.CFrame = CFrame.new((handlepos + mouse.Hit.p)/2, mouse.Hit.p) * CFrame.fromEulerAnglesXYZ(-math.pi/2,0,0)
		beam.Parent = Tool
	end
	local human = getHumanoid(Tool.Parent)
	if human == nil then
		human = Tool.Parent:findFirstChild("Humanoid")
	end
	TorsoConnection = human.Changed:connect(function() onMove(mouse) end)
	ArmConnection = Tool.Parent.Torso["Right Shoulder"].Changed:connect(function() onMove(mouse) end)
	human.Died:connect(function()
		beam.Parent = nil
		beam.Mesh.Scale = Vector3.new(0.25,1,0.25)
		clearEffectScripts()
		effect = script.Parent.LaserEffectScript:clone()
		effect.Disabled = false
		effect.Parent = beam
		end)
	while down do
		if not down then break end
		if ammoLimit.Value then
			if ammo.Value <= 0 then
				firing.Value = false
				down = false
				beam.Parent = nil
				beam.Mesh.Scale = Vector3.new(0.25,1,0.25)
				clearEffectScripts()
				effect = script.Parent.LaserEffectScript:clone()
				effect.Disabled = false
				effect.Parent = beam
				break
			elseif firing.Value == true then
				ammo.Value = ammo.Value - 1
			end
		end
		local dist = math.abs((mouse.Hit.p - handlepos).magnitude)
		if dist <= maxDistance then
			sound:play()
		end
		if mouse.Target ~= nil and dist <= maxDistance then
			if getHumanoid(mouse.Target.Parent) ~= nil then
				attack(getHumanoid(mouse.Target.Parent))
			end
		end
		wait(0.1)
	end
end

function onMove(mouse)
	if not down or Tool.Parent.className == "Backpack" then return end
	target = mouse.Target
	local handlepos = (Tool.Handle.CFrame * CFrame.new(0,-0.5,-2)).p
	local dist = math.abs((mouse.Hit.p - handlepos).magnitude)
	if ammoLimit.Value then
		if ammo.Value <= 0 then
			beam.Parent = nil
			beam.Mesh.Scale = Vector3.new(0.25,1,0.25)
			clearEffectScripts()
			effect = script.Parent.LaserEffectScript:clone()
			effect.Disabled = false
			effect.Parent = beam
			down = false
			firing.Value = false
			return
		end
	end
	if dist <= maxDistance then
		firing.Value = true
		beam.Size = Vector3.new(1,math.ceil(dist),1)
		beam.CFrame = CFrame.new((handlepos + mouse.Hit.p)/2, mouse.Hit.p) * CFrame.fromEulerAnglesXYZ(-math.pi/2,0,0)
		if beam.Parent ~= Tool then
			beam.Parent = Tool
		end
	else
		firing.Value = false
		beam.Parent = nil
		beam.Mesh.Scale = Vector3.new(0.25,1,0.25)
		clearEffectScripts()
		effect = script.Parent.LaserEffectScript:clone()
		effect.Disabled = false
		effect.Parent = beam
	end
end

function onButton1Up(mouse)
	down = false
	firing.Value = false
	target = nil
	if TorsoConnection ~= nil then
		TorsoConnection:disconnect()
	end
	if ArmConnection ~= nil then
		ArmConnection:disconnect()
	end
	clearEffectScripts()
	sound:stop()
	mesh.Scale = Vector3.new(0.25,1,0.25)
	beam.Parent = nil
end

function onEquipped(mouse)
	mouse.Icon = "rbxasset://textures/GunCursor.png"
	mouse.Button1Down:connect(function() onButton1Down(mouse) end)
	mouse.Button1Up:connect(function() onButton1Up(mouse) end)
	mouse.Move:connect(function() onMove(mouse) end)
end

script.Parent.Equipped:connect(onEquipped)

Script 2:

script.Parent.Mesh.Scale = Vector3.new(0.25,1,0.25)
while true do
	script.Parent.Mesh.Scale = Vector3.new(0.25,1,0.25)
	for i=0,3 do
		script.Parent.Reflectance = 0.1 * i
		script.Parent.Mesh.Scale = Vector3.new(script.Parent.Mesh.Scale.x + 0.05*i, script.Parent.Mesh.Scale.y, script.Parent.Mesh.Scale.z + 0.05*i)
		wait()
	end
	for i=3,0,-1 do
		script.Parent.Reflectance = 0.1 * i
		script.Parent.Mesh.Scale = Vector3.new(script.Parent.Mesh.Scale.x - 0.05*i, script.Parent.Mesh.Scale.y, script.Parent.Mesh.Scale.z - 0.05*i)
		wait()
	end
	script.Parent.Mesh.Scale = Vector3.new(0.25,1,0.25)
end

2 comments

0

I can’t guarantee I’ll make an answer, but you will want to check lines 222-227. You can’t get the mouse in a server script.

0

This is a free model script as well.