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

How to play local sound with touch and be able to duplicate the part and still work?

Asked by 2 years ago

So I have a folder in Workspace I called SoundEffects and I have different sounds in it with different names like "Complete" for when you go through the complete portal when you beat a level. I made the script in the portals call on the Complete sound in SoundEffects so I could easily duplicate the portals without having to code a bunch of stuff to make it play the sound. The problem is, the sound doesn't play locally, and I can't find a way to be able to easily duplicate it and have it still play the sound locally. I also made it give you exp when you beat the portal and put it in the same script as the sound, but I can take that out and it would be fine. Here is the script I have:

local CoinsGiven = script.CoinsGiven.Value
local ExpGiven = script.ExpGiven.Value
local CompleteSound = game.Workspace.SoundEffects.Complete

local debounce = true
local bounce = .5
script.Parent.Touched:Connect(function(Hit)
    if Hit.Parent:FindFirstChild("Humanoid") ~= nil then
        local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
        if Player and debounce then
            debounce = false
            Player.leaderstats.Coins.Value = Player.leaderstats.Coins.Value + CoinsGiven
            Player.Exp.Value = Player.Exp.Value + ExpGiven
            CompleteSound:Play()
            wait(bounce)
            debounce = true
        end
    end
end)

Can anyone help me play the sound locally, while still being able to easily copy the part?

Answer this question