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

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

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)

3 comments

0

Is the parent of the script the tool or the handle?

0

The script is in the tool not the handle :{

0

looks like someone already answered ur question but use task.wait() instead of wait() btw

1 answer

✓ Accepted answer

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. ^^

1 comment

0

Someone has helped me with pretty much the same answer, thanks for the response.

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