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

How can I get this TextButton script to work?

Asked by
jtp40 7
8 years ago

I can't figure out how to make this text button trigger/work. Here is the closest I've gotten. StarterGui.ScreenGui.TextButton.RageQuitScript(local script)

local button = script.Parent
button:WaitForChild("Sound")

local function onButtonClick()

    local imageLabel = Instance.new("ImageLabel")

    imageLabel.Parent = script.Parent

    imageLabel.Size = UDim2.new(0.25, 0, 0.25, 0)

    imageLabel.Position = UDim2.new(0, 0, 0, 0)

    imageLabel.Image = "rbxassetid://99995960"

    local sound = Instance.new("Sound")

    sound = "rbxassetid://198460934"

    sound:Play()

    wait(41.613)

    sound:Stop()

    wait(0.01)

    imageLabel.Image = "rbxassetid://36169651"

    sound = "rbxasssetid://223103466"

    sound:Play()

    wait(5)

    sound:Stop()

    wait(0.01)

    imageLabel.Image = "rbxassetid://84899195"

    sound = "rbxassetid://374355709"

    sound:Play()

    wait(53.237)

    sound:Stop()

    wait(0.01)

    imageLabel.Image = "rbxassetid://36169651"

    sound = "rbxasssetid://223103466"

    sound:Play()

    wait(5)

    sound:Stop()

    wait(0.01)

end
button.MouseButton1Click:connect(onButtonClick)

Edit 1: I got the sound to be parented, but the gui still isn't working game.StarterGui.MagicScreenGui.TextButton.RageQuitScript

 local button = script.Parent
button:WaitForChild("Sound")

local function onButtonClick()

    local imageLabel = Instance.new("ImageLabel")

    imageLabel.Parent = script.Parent

    imageLabel.Size = UDim2.new(0.25, 0, 0.25, 0)

    imageLabel.Position = UDim2.new(0, 0, 0, 0)

    imageLabel.Image = "rbxassetid://99995960"

    local sound = Instance.new("Sound")

    local TextButton = game.StarterGui.MagicScreenGui.TextButton --Only change is here

    sound.Parent = TextButton --And there

    sound = "rbxassetid://198460934"

    sound:Play()

    wait(41.613)

    sound:Stop()

    wait(0.01)

    imageLabel.Image = "rbxassetid://36169651"

    sound = "rbxasssetid://223103466"

    sound:Play()

    wait(5)

    sound:Stop()

    wait(0.01)

    imageLabel.Image = "rbxassetid://84899195"

    sound = "rbxassetid://374355709"

    sound:Play()

    wait(53.237)

    sound:Stop()

    wait(0.01)

    imageLabel.Image = "rbxassetid://36169651"

    sound = "rbxasssetid://223103466"

    sound:Play()

    wait(5)

    sound:Stop()

    wait(0.01)

end
button.MouseButton1Click:connect(onButtonClick)

Edit 2: To be more specific, NOTHING IS TRIGGERING. It's probably the button click not working but I don't know how to fix it.

Edit 3: I've taken all of eLunates suggestions, she fixed the sound(thanks), but I'm not even getting the event to trigger at all.

game.StarterGui.MagicScreenGui.TextButton.RageQuitScript

local button = script.Parent
button:WaitForChild("Sound")
local PlayerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")

local function onButtonClick()

    print("Wow!")

    local imageLabel = Instance.new("ImageLabel")

    imageLabel.Parent = script.Parent

    imageLabel.Size = UDim2.new(0.25, 0, 0.25, 0)

    imageLabel.Position = UDim2.new(0, 0, 0, 0)

    imageLabel.Image = "rbxassetid://99995960"

    local sound = Instance.new("Sound")

    local TextButton = game.StarterGui.MagicScreenGui.TextButton

    sound.Parent = TextButton

    sound.SoundId = 198460934

    sound:Play()

    wait(41.613)

    sound:Stop()

    wait(0.01)

    imageLabel.Image = "rbxassetid://36169651"

    sound.SoundId = 223103466

    sound:Play()

    wait(5)

    sound:Stop()

    wait(0.01)

    imageLabel.Image = "rbxassetid://84899195"

    sound.SoundId = 374355709

    sound:Play()

    wait(53.237)

    sound:Stop()

    wait(0.01)

    imageLabel.Image = "rbxassetid://36169651"

    sound.SoundId = 223103466

    sound:Play()

    wait(5)

    sound:Stop()

    wait(0.01)

end
button.MouseButton1Click:connect(onButtonClick)

"Wow!" does not print, which means the event is never even triggered in the first place, so it isn't the sound's fault.

0
Updated my answer to show what else you're doing wrong. User#6546 35 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

You never Parent the Sound to anything

Over at line 16, you make a new Sound, and on line 20 you start Playing it, but it's never Parented to anything and as a result you don't hear it. Consider Parenting it to the Button or some other member of the PlayerGui.

You also replaced Sound

On line 18, which I disregarded, you change the sound variable to a string. That is wrong, as you should instead be setting the SoundId property of the Sound.

0
I parented the sound button, but the gui never shows up and the sound doesn't work still either. jtp40 7 — 8y
0
I added print("Wow!") after the local function, it's not printing. I'm not triggering the event at all. jtp40 7 — 8y
Ad

Answer this question