Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Gamemode Selection Doesn't work properly?

I'm trying to make a gamemode selection, I use an Int Value and I did that if the value is 0 it makes the text say Solo, If it's 1 it makes it say Duo (Team of 2). The problem is that when I press the previous gamemode button and it says solo it doesn't do anything, But if it says Duo it makes it say Solo but I want it to when it says Solo and I press it, The text says Duo (Team of 2).

This is my first script:

local Gamemode = script.Parent
local Next = Gamemode.NextGamemode
local Previous = Gamemode.PreviousGamemode
local GamemodeValue = Gamemode.GamemodeValue

Next.MouseButton1Click:connect(function()
	GamemodeValue.Value = GamemodeValue.Value + 1
end)

Previous.MouseButton1Click:connect(function()
	if GamemodeValue.Value == 0 then
		GamemodeValue.Value = 1
	end
	
	if GamemodeValue.Value == 1 then
		GamemodeValue.Value = 0
	end
end)

This is my second script:

local ChosenGamemode = script.Parent.Parent.ChosenGamemode

while true do
	wait(0.01)
	
	-- Gamemode Limit
	
	if script.Parent.Value == 2 then
		script.Parent.Value = 0
	end
	
	--  Gamemode Text
	
	if script.Parent.Value == 0 then
		ChosenGamemode.Text = "Solo"
	end
	
	if script.Parent.Value == 1 then
		ChosenGamemode.Text = "Duo (Teams of 2)"
	end
end

Btw, This script is inside the Int Value.

Thanks, MajinBluee

1 answer

First of all, you should use the .Changed event to detect when the value changes, rather than a consant loop. You should also use elseif for cleaner code.

script.Parent.Changed:Connect(function(NewVal)
	if NewVal > 1 then
		script.Parent.Value = 0
		NewVal = 0
	end
	local Text = ChosenGamemode.Text
	if NewVal == 0 then
		Text = "Solo"
	elseif NewVal == 1 then
		Text = "Duo (Teams of 2)"
	end
	ChosenGamemode.Text = Text
end)

4 comments

0

That doesn't work

0

Errors? If not, add prints to see where it goes wrong.

0

I did a print on each thing and all of this is fine, But it's not working

0

Is it a LocalScript inside the gui?

This discussion is preserved as it was. New answers, comments, and votes are closed.