Text Button Code Error

Hey devs!

I’ve been stuck on this code for quite a while and don’t seem to get the problem.
Anyone know the problem?

local button = script.Parent
local num = 0

button.Text = "JOIN  " .. num .. "/2"
button.MouseButton1Click:Connect(function()
	num += 1
	if button.Text == "JOIN  2/2" then
		print("ENOUGH PLAYERS!")
	end
end)

Thanks for reading!

1 Like

You are joining text with numbers, you could make

button.Text = "JOIN " … tostring(num)… “/2”

what changed here is that the function tostring changes the number value to a string value.
Other thing is that when adding a value you always have to do it like this: num = num +1
also i see that you are not updating the players number, Heres the correct Version

local button = script.Parent
local num = 0

button.Text = "JOIN " … num … “/2”

button.MouseButton1Click:Connect(function()

if button.Text == “JOIN 2/2” then
print(“ENOUGH PLAYERS!”)
else
num = num +1
button.Text = “JOIN “…tostring(num)…”/2”
print(button.Text)
end
end)

1 Like

Now it works but I can’t seem to get it to stop increasing when it gets to the max limit eg. 2.

so ENOUGH PLAYERS its not printing?

Yes it is but the number wont stop at the limit when it.

local button = script.Parent
local num = 0

button.Text = "JOIN  " .. tostring(num) .. "/2"
button.MouseButton1Click:Connect(function()
if num == 2 then
print("pro gaming we have enough players")
else
	num += 1 
	end
end)

this should work

local button = script.Parent
local num = 0

button.Text = "JOIN  " .. num .. "/2"
button.MouseButton1Click:Connect(function()
if num == 2 then
   print("ENOUGH PLAYERS!")
else
	num += 1
end)

try this

Try This, now it checks if the number its 2 or other to then proceed to add the number.

local button = script.Parent
local num = 0

button.Text = "JOIN " … num … “/2”

button.MouseButton1Click:Connect(function()

if button.Text == “JOIN 2/2” then
print(“ENOUGH PLAYERS!”)
elseif num ~= 2 then
num = num +1
button.Text = “JOIN “…tostring(num)…”/2”
print(button.Text)
end
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.