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

Music OnTouch Help?

Asked by
Tynezz 0
10 years ago

I'm begging you too help...

So, I have a brick. When I touch that brick it would check in the player who touched it's PlayerGui. If it finds a sound in there then stop it. All of them. Then clones one to the playergui and plays it. This is my script. There is no output.

script.Parent.Touched:connect(function(hit) local hum = hit.Parent:FindFirstChild("Humanoid") if hum then local player = game.Players:GetPlayerFromCharacter(hit.Parent) children = player:WaitForChild("PlayerGui"):GetChildren() for i = 1, #children do if children[i].ClassName == "Sound" then children[i]:Stop()

local music = game.Soundscape.Mainsound music:Clone().Parent = player:WaitForChild("PlayerGui") end end end

end) How to fix?

0
Use Lua Text Box. HexC3D 830 — 10y

3 answers

Log in to vote
0
Answered by
bobder2 135
10 years ago
script.Parent.Touched:connect(function(hit) 
    local hum = hit.Parent:FindFirstChild("Humanoid") 
    if hum then
         local player = game.Players:GetPlayerFromCharacter(hit.Parent) 
        children = player:WaitForChild("PlayerGui"):GetChildren() 
        for i = 1, #children do
             if children[i].ClassName == "Sound" then 
                children[i]:Stop()
                local music = game.Soundscape.Mainsound music:Clone()
                music.Parent = player:WaitForChild("PlayerGui") 
                music:Play()
            end
        end 
    end
end

The script above should work just fine, but I haven't tried it.

The problem was here that you weren't actually playing the music. You were just putting it where it should be. To play a sound use: Sound:Play()

Ad
Log in to vote
0
Answered by 10 years ago

Here, I edited your script, it should work now;

--Looks allot like another language, huh? :P 
local debounce = false --Added debounce :)
script.Parent.Touched:connect(function(plr)
if not debounce then
debounce = true
if plr.Parent:FindFirstChild("Humanoid") then
find=game.Players:GetPlayerFromCharacter(plr.Parent)
if find:FindFirstChild("PlayerGui") then
if find.PlayerGui:FindFirstChild("Mainsound") then
find.PlayerGui.Mainsound:Stop()
find.PlayerGui.Mainsound:Destroy()
else
if game.Soundscape:FindFirstChild("Mainsound") then
game.Soundscape.Mainsound:Clone().Parent=find.PlayerGui
wait(.50)
find.PlayerGui.Mainsound:Play()
else
print("Mainsound doesn't exist")
end end
else
print("PlayerGui doesn't exist")
end
else
print("Humanoid doesn't exist")
end
wait(2) --Wait time for debounce
debounce = false
end end)

I hope this helped!

Log in to vote
0
Answered by
MrFlimsy 345 Moderation Voter
10 years ago
local deb = false
script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        if deb == false then
        deb = true
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        repeat wait() until player:FindFirstChild("PlayerGui")
        children = player.PlayerGui:GetChildren()
        for _,v in pairs(children) do
            if v:IsA("Sound") then
                v:Stop()
            end
        end
        local music = game.Soundscape.Mainsound:clone()
        music.Parent = player.PlayerGui
        music:Play()
        wait(1)
        deb = false
        end
    end
end)

This should work.

Edit: Dang, I'm two posts late

Answer this question