|
Hey guys me again, and I've run into a problem with a script. It's supposed to play the song Radioactive by Imagine Dragons when you press the gui button. Well it's not exactly working.
Here's the script:
local screenGui = Instance.new("ScreenGui")
screenGui.Parent = script.Parent
local frame = Instance.new("Frame")
frame.Parent = screenGui
frame.Position = UDim2.new(0, 25, 0, 40)
frame.Size = UDim2.new(0,125,0,200)
local textButton = Instance.new("TextButton")
textButton.Parent = frame
textButton.Position = UDim2.new(0,0,0,0)
textButton.Size = UDim2.new(0,125,0,50)
textButton.BackgroundColor3 = BrickColor.Red().Color
textButton.Text = "Radioactive"
textButton.MouseButton1Down:connect(function()
SoundId = "http://roblox.com//?id=131111368"
sound:Play()
end)
The sounds are preloaded in another script, and if it's needed I'll show it to you. Thanks you for taking the time to read this and hopefully you can help out a beginning scripter.
-BlackVengeance |
|
128GBJoin Date: 2014-04-17 Post Count: 8056 |
textButton.MouseButton1Down:connect(function()
SoundId = "http://roblox.com//?id=131111368"
sound:Play()
end)
You never told the script what "sound" was
Also you are just setting SoundId as an unused variable. |
|
|
Ooh XD I was following the tutorial on the wiki and it just had it as sound:Play()
so I didn't know what was going on. Thanks for pointing that out! |
|
|
So uhm... I managed to run into yet another problem. I went to the script that preloads the song and changed it to this:
sound = Instance.new("Sound")
sound.SoundId = "http://roblox.com/?id=131111368"
when I run the game it does the same thing it's been doing (not letting the sound play)
I looked in the Output window and this is what I get from it:
02:17:16.697 - Players.Player1.PlayerGui.LocalScript:30: attempt to index global 'sound' (a nil value)
02:17:16.698 - Stack Begin
02:17:16.699 - Script 'Players.Player1.PlayerGui.LocalScript', Line 30
02:17:16.700 - Stack End
02:17:16.700 - Disconnected event because of exception
Sorry if it seems I'm asking a lot but I in all honestly don't know what is going on, so thank you for taking the time to read this and answering the questions.
-BlackVengeance.
oh btw, I edited the function in the gui. It looks like this now:
textButton.MouseButton1Down:connect(function()
sound:Play()
end) |
|
128GBJoin Date: 2014-04-17 Post Count: 8056 |
You didn't parent the sound
sound = Instance.new("Sound", script) --Change script to Workspace or somewhere serverside if you want it to be a non local sound
Also why not just have the sound already exist? Why even need to create it from the script? |
|
|
To answer your question I thought it would be better to create from a script since I was scripting a gui along with it.
And I sorta did a rewrite of the script so the one that preloads the sounds and the gui script are one of the same, and the sounds are now stored in an array.
... this scripting thing is A LOT harder than I thought... |
|
|
Also, I've had exactly one day of Sound experience, but everything I've seen looked like you created Sound objects and reference them in script. What's the pros/cons with on the fly instantiation as opposed to having objects in scripts? |
|