Hi! I'm just now dabbling in ROBLOX programming (with no prior coding knowledge) so my code will be very crude, so bear with me.
I'm creating a surface GUI that has a large image button in the middle, and two image buttons on either side to cycle the middle image. I don't know the best way to do this, so so far I have a script in the left and right buttons that increases or decreases a _G variable by one every time you click. It looks like this:
script.Parent.MouseButton1Click:connect(function()
_G.song = _G.song + 1
end)
Then I have another script in the big central image button that is supposed to detect if the _G variable equals either 1 or 2, and plays a different song on click depending on the value of the variable. The code looks like this:
mus1=workspace.juke.buttons.music1
mus2=workspace.juke.buttons.music2
while true do
if _G.song == 1 then
script.Parent.MouseButton1Click:connect(function(one)
mus1:Play()
end)
elseif _G.song == 2 then
script.Parent.MouseButton1Click:connect(function(two)
mus2:Play()
end)
end
wait(.25)
end
When I click the big central button however, it plays both songs, not one or the other. Why is it playing both?

1 comment
math.random is actually "random" though