Ad
Log in to vote
1

Can Someone Help Me?, I Need Help With The Sounds! (Bad English, Sorry)

Asked by 15 days ago

I'm New At Script But, I Was Making The Gun Script With Youtube Tutorial, And Realized When I Testing Gun With My Friend, I Hear The Shoot Sound, But The Friend Can't Hear The Sound, When Friend Shoot, I Don't Hear It., I Did Disable Some Other Script, But It Doesn't Worked.

local gun = script.Parent
local firesound = gun:WaitForChild("Handle").Shoot
local equipsound = gun.Handle.Equip
local emptysound = gun.Handle.ClipEmpty
local reloadsound = gun.Handle.Reload
local player = game.Players.LocalPlayer
local clipsize = gun:WaitForChild("Ammo").Value
local ammo = gun:WaitForChild("Ammo")
local chara = player.Character or player.CharacterAdded:Wait()
local hum = chara:WaitForChild("Humanoid")

local userInput = game:GetService("UserInputService")

local mouse = game.Players.LocalPlayer:GetMouse()

mouse.Icon = "rbxassetid://4727564972"

local replicatedstorage = game:GetService('ReplicatedStorage')
local event = replicatedstorage:WaitForChild('PistolFire')

gun.Equipped:Connect(function(mouse)

    local anim2 = hum:LoadAnimation(script.Parent.Equip)
    local current2 = anim2
    current2:Play()

    equipsound:Play()

    player.PlayerGui.AmmoGui.Ammo.Visible = true
    player.PlayerGui.AmmoGui.Ammo.Text = "Ammo: " .. tostring(ammo.Value) .. " / " .. gun.MaxAmmo.Value

    mouse.Button1Down:Connect(function()
        if gun.Ammo.Value > 0 then
            event:FireServer(gun.Handle.Position, gun.Handle.Orientation, mouse.Hit.p)
            firesound:Play()
            local anim = hum:LoadAnimation(script.Parent.Animation)
            local current = anim
            current:Play()
            gun.Ammo.Value = gun.Ammo.Value - 1
        else
            emptysound:Play()
        end
    end)

    mouse.Button2Down:Connect(function()

        local camera = game.Workspace.CurrentCamera

        camera.FieldOfView = 40

    end)

    mouse.Button2Up:Connect(function()

        local camera = game.Workspace.CurrentCamera

        camera.FieldOfView = 70

    end)

end)

gun.Unequipped:Connect(function()
    player.PlayerGui.AmmoGui.Ammo.Visible = false
end)

userInput.InputBegan:Connect(function(input, gameProcessed)

    if not gameProcessed then
        if input.UserInputType == Enum.UserInputType.Keyboard then
            local keycode = input.KeyCode
            if keycode == Enum.KeyCode.R then
                if gun.Ammo.Value < clipsize and gun.MaxAmmo.Value > 0 then
                    reloadsound:Play()
                    local anim3 = hum:LoadAnimation(script.Parent.Reload)
                    local current3 = anim3
                    current3:Play()
                    reloadsound.Ended:Wait()
                    if gun.MaxAmmo.Value - (clipsize - gun.Ammo.Value) >= 0 then
                        gun.MaxAmmo.Value = gun.MaxAmmo.Value - (clipsize - gun.Ammo.Value)
                        gun.Ammo.Value = clipsize
                    else
                        gun.Ammo.Value = gun.Ammo.Value + gun.MaxAmmo.Value
                        gun.MaxAmmo.Value = 0
                        player.PlayerGui.AmmoGui.Ammo.Text = "Ammo: " .. tostring(ammo.Value) .. " / " .. gun.MaxAmmo.Value
                    end 

                end 
            end
        end
    end 
end)

ammo.Changed:Connect(function()
    player.PlayerGui.AmmoGui.Ammo.Text = "Ammo: " .. tostring(ammo.Value) .. " / " .. gun.MaxAmmo.Value
end)

3 answers

Log in to vote
1
Answered by 15 days ago

I see that it’s in the client. If it’s played in the client, it will only play to the LocalPlayer. Jnstead, Use remote events to send the sound to the server and play it. When the server plays a sound, all players can hear it. You don’t need ti disable other scripts.

-- In Gun script (Client)

RemoteEvent:FireServer(Sound)
-- RemoteEvent Script (Server)

RemoteEvent.OnServerEvent:Connect(function(Player, Sound)
   Sound:Play()
end)

For more info about RemoteEvents, click here.

0
Thanks You For Teaching Me This Kindfully! :D Hiktius 5 — 15d
0
Its better to use a serverscript to handle tools because exploiters can spam the remote unless there is a debounce on the server Kingu_Criminal 111 — 15d
Ad
Log in to vote
0
Answered by 15 days ago

I advise you to use a serverscript to handle your tool instead of a localscript. But as the other answer said, if you are using a localscript then fire a remote to the server telling it to play the sound. If you are looking for scripters, I don't mind helping

0
Don't help him he's kinda gay Wrathoxicihatehim 5 — 15d
0
what do you mean by that lmaooo Kingu_Criminal 111 — 14d
0
that's gay LYESPILLEDINMYEYES -14 — 14d
Log in to vote
0
Answered by 14 days ago

I think you're using a local script, you're going to need a regular script to execute the sounds.

Answer this question