I’m making a computer system for a game I’m making and this script isn’t working, can someone help?
-- Main commands
local maincommands = {
store = "store"
}
-- Subcommands
local subcommands = {
deny = "deny",
confirm = "confirm"
}
-- Checks if its a valid command
function isValidCommand(input, commandList)
for _, command in ipairs(commandList) do
if input == command then
return true
end
end
return false
end
-- This is the function that handles everything
local function onEnterPressed()
local userInput = script.Parent.Text:lower():gsub("^%s*(.-)%s*$", "%1") -- Trim spaces and convert to lowercase
-- Check if the input is a valid main command
if isValidCommand(userInput, maincommands.store) then
print("Valid main command: Store")
script.Parent.Parent.ScrollingFrame.TextLabel.Text = "Welcome to the store! Items are listed below!\n*Placeholder $5"
end
-- Check if the input is a valid sub command
if isValidCommand(userInput, subcommands.confirm) then
print("Valid sub command: Confirm")
end
end
-- Using this to check the command when enter is pressed
script.Parent.FocusLost:Connect(function(enterPressed)
if enterPressed then
onEnterPressed()
end
end)