Hello there! I have been doing a small scripting project to practice scripting.
I ran into an issue that is when I click a text button, it changes to a different word on the text button, and plays music, though when I click the button again, the music replays. Is there anyway to make it so when I click the button, the text changes and the music plays, but if I click it again it does not replay the song? I am hoping so that when I click it a second time it does something else.
Please note I am not a professional scripter so this will probably look messy to you actual scripters out there!
script.Parent.MouseButton1Click:Connect(function(click)
clickCount=clickCount+1
script.Parent.Text = “Hit”
wait(1)
if clickCount==1 then Game.Workspace.Music1:Play() end
if clickCount>1 then
– do something else here
end
All you need is an if statement checking if it’s been clicked before. Something like this:
-- Objects
local Button = script.Parent
local Music = workspace.Music1
-- Variables
local NumClicks = 0
-- Functions
local function OnClick()
NumClicks += 1
Button.Text = "Hit"
wait(1)
if NumClicks == 1 then
Music:Play()
else
-- A different action
end
end
-- Functionality Code
Button.MouseButton1Click:Connect(OnClick)
Note: Variable += 1 is just another way of saying Variable = Variable + 1