Making Undertale button system

Hi,

I’m making an Undertale game in Roblox but I’m stuck in the button system. I’m trying to recreate the button system in Undertale using the NextSelection, I found a forum that uses the same method it works perfectly but I can’t customize the selected button.

The issue.

This happens when I click Left then Right or Right then Left
Also, when I click Left or Right the color is set to Item even though the Fight is the default set

Here’s the script to understand more.

local UIS = game:GetService("UserInputService")

local screenGui = script.Parent

local buttonFrame = screenGui:WaitForChild("ButtonFrame")
local fight = buttonFrame:WaitForChild("Fight")
local act = buttonFrame:WaitForChild("Act")
local item = buttonFrame:WaitForChild("Item")
local mercy = buttonFrame:WaitForChild("Mercy")

local curSel = fight

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Left then
		if curSel.NextSelectionLeft then
			curSel.NextSelectionLeft.BackgroundColor3 = Color3.fromRGB(27, 42, 52)
			curSel = curSel.NextSelectionLeft
			curSel.NextSelectionLeft.BackgroundColor3 = Color3.fromRGB(104, 116, 172)
		end
	elseif input.KeyCode == Enum.KeyCode.Right then
		if curSel.NextSelectionRight then
			curSel.NextSelectionRight.BackgroundColor3 = Color3.fromRGB(27, 42, 52)
			curSel = curSel.NextSelectionRight
			curSel.NextSelectionRight.BackgroundColor3 = Color3.fromRGB(104, 116, 172)
		end
	end
end)

And here is the button layout

The NextSelection of Fight and Mercy is set up to go around the buttons when the cursel is set to Fight and the player clicks Left it goes back to Mercy this also applies to Mercy.

The Act NextSelectionLeft is set to Fight and NextSelectionRight is set to Item this setting also applies to Item.

sorry for the messy post and script.

Thanks

2 Likes

You also need to set it so when ever you changed from right to left curSel.NextSelectionRight is set to the disabled color

2 Likes

Should I flip the 2 lines?

ssssssssssssssssssssssssssssssssssssssssssssssssssssss

1 Like

No need. the easy fix is just adding a new code flipping the 2 won’t make any difference:

local UIS = game:GetService("UserInputService")

local screenGui = script.Parent

local buttonFrame = screenGui:WaitForChild("ButtonFrame")
local fight = buttonFrame:WaitForChild("Fight")
local act = buttonFrame:WaitForChild("Act")
local item = buttonFrame:WaitForChild("Item")
local mercy = buttonFrame:WaitForChild("Mercy")

local curSel = fight

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Left then		
		if curSel.NextSelectionLeft then
			curSel.NextSelectionLeft.BackgroundColor3 = Color3.fromRGB(27, 42, 52)
			curSel.NextSelectionRight.BackgroundColor3 = Color3.fromRGB(27, 42, 52) -- This is the fix
			curSel = curSel.NextSelectionLeft
			curSel.NextSelectionLeft.BackgroundColor3 = Color3.fromRGB(104, 116, 172)
			
		end
	elseif input.KeyCode == Enum.KeyCode.Right then
		if curSel.NextSelectionRight then
			curSel.NextSelectionRight.BackgroundColor3 = Color3.fromRGB(27, 42, 52)
			curSel.NextSelectionLeft.BackgroundColor3 = Color3.fromRGB(27, 42, 52) -- This is the fix
			curSel = curSel.NextSelectionRight
			curSel.NextSelectionRight.BackgroundColor3 = Color3.fromRGB(104, 116, 172)
		end
	end
end)
2 Likes

It’s fixed only one of the buttons is colored but I found an issue again when I click left a couple of times it works but when I switch to right it goes to left then when I click again it continues to go right this also applies when I go right then left. I’m confused what’s the issue of this I thought it works perfectly.

1 Like

Hmm, maybe doing something like this will help:

local UIS = game:GetService("UserInputService")

local screenGui = script.Parent

local buttonFrame = screenGui:WaitForChild("ButtonFrame")
local fight = buttonFrame:WaitForChild("Fight")
local act = buttonFrame:WaitForChild("Act")
local item = buttonFrame:WaitForChild("Item")
local mercy = buttonFrame:WaitForChild("Mercy")

local curSel = fight

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Left then		
		if curSel.NextSelectionLeft then
			curSel.NextSelectionLeft.BackgroundColor3 = Color3.fromRGB(104, 116, 172)
			curSel.NextSelectionRight.BackgroundColor3 = Color3.fromRGB(27, 42, 52)
			curSel = curSel.NextSelectionLeft
			curSel.NextSelectionRight.BackgroundColor3 = Color3.fromRGB(27, 42, 52)
		end
	elseif input.KeyCode == Enum.KeyCode.Right then
		if curSel.NextSelectionRight then
			curSel.NextSelectionRight.BackgroundColor3 = Color3.fromRGB(104, 116, 172)
			curSel.NextSelectionLeft.BackgroundColor3 = Color3.fromRGB(27, 42, 52)
			curSel = curSel.NextSelectionRight
			curSel.NextSelectionLeft.BackgroundColor3 = Color3.fromRGB(27, 42, 52)
		end
	end
end)
2 Likes

It works! Sorry for the late response

2 Likes