First of all, it's a gui button, so you don't need to use a "function"; and maybe adding :WaitForChild() in each line, or defining variables may hope majorly.
Your code is ugly, un-organized and plain old and shifty.. (No offense!)
function click()
script.Parent.Parent.Parent.Parent.Parent.Sound:Stop()
script.Parent.Parent.Parent.Parent.Parent.Sound.SoundId = 'rbxassetid://251979407'
script.Parent.Parent.Parent.Parent.Parent.Sound:Play()
script.Parent.Parent.Parent.frame.music.Image = 'rbxassetid://339386472'
script.Parent.Parent.Parent.frame.Text = ' '
end
script.Parent.MouseButton1Click:connect(click)
So here's (hopefully) the fixed version, organized and spacious version; with helpful taglines aka comments to hopefully help you understand what's going on with each line of code.
I hope this helped and will also help you in the future,
regards,
Asperanator.
Fixed version(hopefully):
local button = script.Parent
local sound = script.Parent.Parent.Parent.Parent:WaitForChild("Sound")
local frame = script.Parent.Parent:WaitForChild("frame")
local music = frame:WaitForChild("music")
button.MouseButton1Down:connect(function()
sound:Stop()
sound.SoundId = 'rbxassetid://251979407'
sound:Play()
music.Image = 'rbxassetid://339386472'
frame.Text = " "
end)
If that doesn't work, add .Parent in the frame & sound variable.
Hope this helped if not; contact me on ROBLOX: Asperanator - http://www.roblox.com/users/85640404/profile
And if this helped please give it the "arrow up", or "thumbs up"..
2 comments
Hmm... I know what you mean, I've actually had this problem before. It just seemed to clone itself. Try adding a few waits
https://scriptinghelpers.org/blog/it-works-in-studio-but-not-online