Hi! I’m trying to create a way to make sure no one can select multiple things at a time in my self check-in. As you can see in the video below it works just fine for the top one but not anyone else. It is supposed to say false if a class is already selected, and if the class selected is the one you clicked on it will unselect.
The frames have the same script and formatting. The reason I do this is because I have a frame creation system that creates a frame based on a number in a module script.
Local script:
local function stopAtDifferentValue(f) --"f" is a folder of value instances.
for _, valueInstance in ipairs(f:GetDescendants()) do
if valueInstance:IsA("TextLabel") and valueInstance.Name == "statusText" then
if valueInstance.Text == "Selected" or valueInstance.Text == "Unselect" then
return false
else
return true
end
end
end
end
script.Parent.SelectBtn.MouseButton1Click:Connect(function()
local result = stopAtDifferentValue(ClassFrames)
print(result)
if script.Parent.Frame.statusText.Text == "Selected" or script.Parent.Frame.statusText.Text == "Unselect" then
script.Parent.Frame.statusText.Text = "Select"
script.Parent.Frame.BackgroundColor3 = Color3.fromRGB(114, 152, 98)
game.ReplicatedStorage.SCIstorage.Functions.SRE:FireServer("unselect", moduleName)
end
if result == true then
if script.Parent.Frame.statusText.Text == "Select" then
script.Parent.Frame.statusText.Text = "Selected"
script.Parent.Frame.BackgroundColor3 = Color3.fromRGB(226, 134, 28)
game.ReplicatedStorage.SCIstorage.Functions.SRE:FireServer("select", moduleName)
end
end
end)
1)Notice that you’ve fired the server ‘select’ and ‘unselect’ with low caps, and you’re checking for these words with upper caps
2)You should loop for each frame that you have there, if the player hasnt chosen one yet [or unselected a previous one], then he’d be able to choose them
“script.Parent.SelectBtn.MouseButton1Click:Connect(function()” - this would fire only for that specific button you called here, if you want this to work for each of your buttons, make a loop and in that, call the MouseButton1Click for each of the buttons when a player is pressing them
“script.Parent.SelectBtn.MouseButton1Click:Connect(function()” - this would fire only for that specific button you called here, if you want this to work for each of your buttons, make a loop and in that, call the MouseButton1Click for each of the buttons when a player is pressing them
the same script is inside every frame tho? So should I place the script in the classFrames or something and make a loop finding the buttons then if they get clicked they run the same code?
local sci = require(game.Workspace.AeroSCI.README)
game.ReplicatedStorage.SCIstorage.Functions.SRE.OnServerEvent:Connect(function(plr, event, class)
if event == "select" then
if plr.sci.selected.Value == false then
plr.sci.selected.Value = true
plr.sci.selectedClass.Value = class
end
elseif event == "unselect" then
if plr.sci.selected.Value == true then
plr.sci.selected.Value = false
plr.sci.selectedClass.Value = ""
end
end
end)
game.Players.PlayerAdded:Connect(function(plr)
local sciFolder = Instance.new("Folder", plr)
sciFolder.Name = "sci"
local selectedValue = Instance.new("BoolValue", sciFolder)
selectedValue.Name = "selected"
local selectedClass = Instance.new("StringValue", sciFolder)
selectedClass.Name = "selectedClass"
local function CloneTemplate(guiName)
local gui = game.ReplicatedStorage.SCIstorage.Misc.Template:Clone()
gui.Parent = game.ReplicatedStorage.SCIstorage.SCI.MainFrame.CheckInFrame.AttributeFrame.ClassFrames
gui.Name = guiName
return gui
end
for k = 1,sci.Classes do
CloneTemplate(k)
end
end)