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

Why can't anyone hear or see other players holding gun?

Hello, i am making a pistol for a shooting range practice, However no one seems to see the other players gun being held or can be heard? Is this a cause of Filter Enable? Or Poor Scripting Codes?

If The FilterEnable, How can i make these code works for FilterEnabled?

wait(0.5)
local player = game.Players.LocalPlayer
local pgui = player.PlayerGui
local character = player.Character
local humanoid = character.Humanoid
local head = character.Head
local tool = script.Parent
local handle = tool.Handle
local pl_mouse = player:GetMouse()

local assetlink = "http://www.roblox.com/asset/?id="
Settings = {
	unlimited_ammo = true,
	clip_size = 8,
	cooldown = 0.05,
	reload_time = 2.5,
	damage = 4,
	head_damage = 5,
	bullets_per_shot = 1,
	automatic = false,
	inaccuracy = 2,
	distance = 500,
	fire_sound = "132455970",
	fire_vol = 1,
	fire_pitch = 1,
	reload_sound = "132455990",
	reload_vol = 1,
	reload_pitch = 1,
	icon_normal = "54019939",
	icon_reload = "54020165",
	icon_empty = "54019936",
	visualize = false
}

local gamemain = game.Workspace.GameMain
local bdmg = gamemain.ShadowDamage
function HIT_HANDLE(hit, pos)
	if hit == nil then return end
	local h = hit.Parent:findFirstChild("Humanoid")
	if h == nil then
		h = hit.Parent.Parent:findFirstChild("Humanoid")
	end
	if h ~= nil then
		if h.Parent:findFirstChild("ShadowPlayer") ~= nil then
			if hit.Name == "Head" then
				bdmg:FireServer(Settings.head_damage)
			else
				bdmg:FireServer(Settings.damage)
			end
		end
	end
end

local wdi = nil
local gamemodel = game.Workspace:findFirstChild("GameModel")
if gamemodel ~= nil then
	local fm = gamemodel:findFirstChild("MAP")
	if fm ~= nil then
		local md = fm:findFirstChild("MapData")
		if md ~= nil then
			local wd = md:findFirstChild("WeaponDrops")
			if wd ~= nil then
				wdi = wd
			end
		end
	end
end

function GENERATE_IGNORELIST()
	local result = {character, camera}
	if wdi ~= nil then
		result[#result + 1] = wdi
	end
	local plr = game.Players:GetPlayers()
	for i = 1, #plr do
		if plr[i] ~= player then
			local char = plr[i].Character
			if char:findFirstChild("ShadowPlayer") == nil then
				result[#result + 1] = char
			else
				local fkh = char:findFirstChild("FakeHead")
				if fkh ~= nil then
					result[#result + 1] = fkh
				end
				local scy = char:findFirstChild("Scythe")
				if scy ~= nil then
					result[#result + 1] = scy
				end
			end
		end
	end
	return result
end

--GUI
local ggui = Instance.new("ScreenGui")
ggui.Name = "AmmoGUI"
local mfr = Instance.new("Frame", ggui)
mfr.BackgroundColor3 = Color3.new(0, 0.33, 0)
mfr.BorderColor3 = Color3.new(0, 0, 0)
mfr.BackgroundTransparency = 0.2
mfr.Position = UDim2.new(0.5, -75, 1, -145)
mfr.Size = UDim2.new(0, 150, 0, 30)

local gui_clip = Instance.new("TextLabel", mfr)
gui_clip.BackgroundTransparency = 1
gui_clip.Text = ""
gui_clip.Position = UDim2.new(0.5, -29, 1, -30)
gui_clip.Size = UDim2.new(0, 30, 0, 30)
gui_clip.Font = "SciFi"
gui_clip.FontSize = "Size36"
gui_clip.TextColor3 = Color3.new(1, 1, 0)
gui_clip.TextXAlignment = "Right"

local gui_ammo = Instance.new("TextLabel", mfr)
gui_ammo.BackgroundTransparency = 1
gui_ammo.Text = ""
gui_ammo.Position = UDim2.new(0.5, 2, 1, -25)
gui_ammo.Size = UDim2.new(0, 30, 0, 30)
gui_ammo.Font = "SciFi"
gui_ammo.FontSize = "Size18"
gui_ammo.TextColor3 = Color3.new(1, 1, 1)
gui_ammo.TextXAlignment = "Left"
--GUI

rapid_on = false
reloading = false

clip = script.Clip
ammo = script.Ammo

local check = {handle:findFirstChild("Fire"), handle:findFirstChild("Reload")}
if check[1] then check[1]:remove() end if check[2] then check[2]:remove() end

local sound_reload = Instance.new("Sound", handle)
sound_reload.Name = "Reload"
sound_reload.SoundId = assetlink .. Settings.reload_sound
sound_reload.Volume = Settings.reload_vol
sound_reload.Pitch = Settings.reload_pitch

local sound_fire = Instance.new("Sound", handle)
sound_fire.Name = "Fire"
sound_fire.SoundId = assetlink .. Settings.fire_sound
sound_fire.Volume = Settings.fire_vol
sound_fire.Pitch = Settings.fire_pitch

local last_shot = tick()

local find_anim_script = tool:findFirstChild("GunAnimation")
function FireFunction(ps)
	if tick() - last_shot < Settings.cooldown or clip.Value <= 0 or reloading then return end
	last_shot = tick()
	clip.Value = clip.Value - 1
	sound_fire:play()
	if find_anim_script then
		find_anim_script.recoil.Value = true
	end
	local pos1 = head.Position
	local pos2 = ps
	for i = 1, Settings.bullets_per_shot do
		local pos3 = (CFrame.new(pos1, pos2) * CFrame.new(0, 0, -100) * CFrame.new((math.random(-1000, 1000) / 1000) * Settings.inaccuracy, (math.random(-1000, 1000) / 1000) * Settings.inaccuracy, 0)).p
		
		local ray = Ray.new(
			pos1,
			(pos3 - pos1).unit * math.abs(Settings.distance)
		) 
	
		local hit_part, pos = Workspace:FindPartOnRayWithIgnoreList(ray, GENERATE_IGNORELIST(), false)
		coroutine.resume(coroutine.create(function()
			HIT_HANDLE(hit_part, pos)
		end))
		if Settings.visualize then
			local p = Instance.new("Part", Workspace)
			p.Anchored = true
			p.formFactor = "Custom"
			p.BrickColor = BrickColor.new("New Yeller")
			p.Size = Vector3.new(0.2, 0.2, 0.2)
			p.CFrame = CFrame.new(pos)
			p:BreakJoints()
			local m = Instance.new("SpecialMesh", p)
			m.MeshType = "Sphere"
			coroutine.resume(coroutine.create(function()
				wait(2)
				p.Anchored = false
				wait(2)
				p:remove()
			end))
		end
	end
end

equipped = false
died_lock = false
humanoid.Died:connect(function() died_lock = true ggui.Parent = nil end)
clip.Changed:connect(function()
	gui_clip.Text = tostring(clip.Value)
end)
ammo.Changed:connect(function()
	if not Settings.unlimited_ammo then
		gui_ammo.Text = "/" .. tostring(ammo.Value)
	else
		gui_ammo.Text = "/INF"
	end
end)

pl_mouse.KeyDown:connect(function(key)
	if string.lower(key) == "x" and not died_lock and equipped then
		print("DropWeapon")
	end
end)

tool.Equipped:connect(function(mouse)
	equipped = true
	gui_clip.Text = tostring(clip.Value)
	if not Settings.unlimited_ammo then
		gui_ammo.Text = "/" .. tostring(ammo.Value)
	else
		gui_ammo.Text = "/INF"
	end
	ggui.Parent = pgui
	if died_lock then return end
	local this_run = true
	local conn = tool.Unequipped:connect(function()
		this_run = false
	end)
	local conn2 = humanoid.Died:connect(function()
		this_run = false
		died_lock = true
		ggui.Parent = nil
	end)
	local function reloadit()
		if not this_run then return end
		if clip.Value == Settings.clip_size or (ammo.Value == 0 and not Settings.unlimited_ammo) or reloading then return end
		reloading = true
		sound_reload:play()
		gui_clip.Text = "."
		local rstart = tick()
		local rtime = Settings.reload_time
		while tick() - rstart < rtime  do
			wait()
			local amm = (math.floor(((tick() - rstart) / rtime) * 4)) + 1
			gui_clip.Text = string.rep(".", amm)
		end
		local change
		if not Settings.unlimited_ammo then
			change = math.max(0, math.min(Settings.clip_size - clip.Value, ammo.Value))
		else
			change = Settings.clip_size - clip.Value
		end
		clip.Value = clip.Value + change
		if not Settings.unlimited_ammo then
			ammo.Value = ammo.Value - change
		end
		gui_clip.Text = tostring(clip.Value)
		reloading = false
	end
	coroutine.resume(coroutine.create(function()
		while this_run do
			wait()
			if reloading then
				mouse.Icon = assetlink .. Settings.icon_reload
			elseif clip.Value == 0 and ammo.Value == 0 then
				mouse.Icon = assetlink .. Settings.icon_empty
			else
				mouse.Icon = assetlink .. Settings.icon_normal
			end
		end
	end))
	mouse.Button1Down:connect(function()
		if not this_run then return end
		rapid_on = true
		FireFunction(pl_mouse.Hit.p)
		if clip.Value == 0 then
			reloadit()
		end
	end)
	mouse.Button1Up:connect(function()
		if not this_run then return end
		rapid_on = false
	end)
	if clip.Value == 0 then
		reloadit()
	end
	mouse.KeyDown:connect(function(key) if string.lower(key) == "r" then reloadit() end end)
	if Settings.automatic then
		local r_serv = game:GetService("RunService")
		while this_run and not died_lock do
			r_serv.RenderStepped:wait()
			if rapid_on then
				FireFunction(pl_mouse.Hit.p)
				if clip.Value == 0 then
					reloadit()
				end
			end
		end
	end
end)
tool.Unequipped:connect(function(mouse)
	equipped = false
	ggui.Parent = nil
	rapid_on = false
end)

humanoid:EquipTool(tool) --the pistol has to be equipped at start of game

1 comment

0

If the gun is only visible locally then you are only adding the tool on the client, considering i dont see anything here about the gun's model itself inside the tool, id assume the issue is the last line. you can use the EquipTool function on the server instead with the playeradded method for the player  Sounds are heard by clients locally so youd need to play that on the server for all players to

1 answer

✓ Accepted answer

As Serpentine said, anything you do from the client side (meaning a local script) won't be replicated or in other words transferred to the server because of FilteringEnabled as you said. This means that anything you do in the client like inserting a part or changing a property or playing a sound... all of those chnages would only show for that particular client.

Technically to fix this, you have to play the sounds and :EquipTool() in the server so those changes replicate to all other clients and show for everyone (remember server/client replication always has to work, that's why anything done in the server shows up for everyone). So what you have to do is use RemoteEvents, here is a helpful link

2 comments

0

So how can i exactly play the sounds from the gun handle? If the script is going to be in serverscript?

0

@ITSMABBLE145658 you fire a signal to the serverscript whenver you wanna play a sound

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