I’ve been working on a swordfight game and I want to add sounds. Slash sounds are working really well but when it comes to swing sounds, it only plays one time in game and it works perfectly on Studio. Any thoughts?
Studio
Game:
Script:
local tool = script.Parent
local Players = game:GetService("Players")
local db = false
local RepStorage = game:GetService("ReplicatedStorage")
local blade = script.Parent.Union
local CanDamage = script.Parent.CanDamage
local Debris = game:GetService("Debris")
local SoundsFolder = script.Parent:FindFirstChild("Sounds")
local Equip = SoundsFolder:WaitForChild("Equip")
local Swing = SoundsFolder:WaitForChild("Swing")
function TagHumanoid(humanoid, player)
local Creator_Tag = Instance.new("ObjectValue")
Creator_Tag.Name = "creator"
Creator_Tag.Value = player
Debris:AddItem(Creator_Tag, 2)
Creator_Tag.Parent = humanoid
end
function createAnim(char,AnimID)
local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/Asset?ID="..AnimID
local loadedanim = char:FindFirstChild("Humanoid"):LoadAnimation(animation)
loadedanim:Play()
end
function UntagHumanoid(humanoid)
for i, v in pairs(humanoid:GetChildren()) do
if v:IsA("ObjectValue") and v.Name == "creator" then
v:Destroy()
end
end
end
function Damage(hit)
hit.Parent.Humanoid:TakeDamage(math.random(49,51))
end
tool.Equipped:Connect(function()
local char1 = tool.Parent
local player1 = Players:GetPlayerFromCharacter(char1)
local humanoid1 = char1:FindFirstChild("Humanoid")
tool.Activated:Connect(function()
blade.Touched:Connect(function(hit)
local humanoid2 = hit.Parent:FindFirstChild("Humanoid")
if hit.Parent:FindFirstChild("Humanoid") then
if CanDamage.Value then
CanDamage.Value = false
UntagHumanoid(humanoid2)
TagHumanoid(humanoid2, player1)
Damage(hit)
wait(0.9)
CanDamage.Value = true
end
end
end)
end)
end)
tool.Equipped:Connect(function()
Equip:Play()
local char = tool.Parent
local player = Players:GetPlayerFromCharacter(char)
local humanoid = char:FindFirstChild("Humanoid")
tool.Activated:Connect(function()
if db == false then
db = true
Swing:Play()
createAnim(char,"4940451451")
wait(0.9)
db = false
end
end)
end)