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

Sound isn't server-sided in Tool? Please help!

Asked by 2 years ago

So my sound isnt serversided in my game, I want other people to hear the sound when using the tool but it doesnt work...

local swinganimationid = 9671188351


repeat wait() until game.Players.LocalPlayer.Character
local lp = game.Players.LocalPlayer
local sp = script.Parent
local debounce = true
local sound = script.Parent.Sound1
local sound2 = script.Parent.Sound2

local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://" .. swinganimationid
local swingtrack = lp.Character.Humanoid:LoadAnimation(anim)

sp.Activated:connect(function()
    if debounce == true then
        debounce = false
        swingtrack:Play()
        sound:Play()
        sound2:Play()
        wait(swingtrack.Length)
        sound2:Stop()
        sound:Stop()
        debounce = true
    end
end)
0
Is the parent of the script the tool or the handle? MrOctoFoam 0 — 2y
0
The script is in the tool not the handle :{ Meru_Noxeru 9 — 2y
0
looks like someone already answered ur question but use task.wait() instead of wait() btw ZeroToH3ro 82 — 2y

1 answer

Log in to vote
1
Answered by 2 years ago

Add a Script, a LocalScript, and a RemoteEvent in your tool. Inside the LocalScript, make the tool.Activated function:

local swinganimationid = 9671188351


repeat wait() until game.Players.LocalPlayer.Character
local lp = game.Players.LocalPlayer
local sp = script.Parent
local debounce = true

sp.Activated:connect(function()
    if debounce == true then
        debounce = false
        script.Parent.RemoteEvent:FireServer(swinganimationid)
        debounce = true
    end
end)

Then inside the Script, make the animation and the sound play:

local RemoteEvent = script.Parent.RemoteEvent

RemoteEvent.OnServerEvent:Connect(function(plr, animId)
    local anim = Instance.new("Animation")
    anim.AnimationId = "rbxassetid://" .. animId
    local swingtrack = plr.Character.Humanoid:LoadAnimation(anim)

    swingtrack:Play()
    script.Parent.Sound1:Play()
    script.Parent.Sound2:Play()
    wait(swingtrack.Length)
    script.Parent.Sound2:Stop()
    script.Parent.Sound1:Stop()
end)

Hope it helps! Let me know if there are errors and mistakes. ^^

0
Someone has helped me with pretty much the same answer, thanks for the response. Meru_Noxeru 9 — 2y
Ad

Answer this question