You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
i made an locker, and if an player choosed their own locker combination then it will stay like that, and it opens/closes until they stop using the locker then another player can claim it
What is the issue? Include screenshots / videos if possible!
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
yes i tried, but nothing worked.
i am now trying to script an locker system rn but itâs hard because i am a beginner:(
Well, what youâre gonna have to do is check a player interacts with the locker, when they do, make a Text box pop up that allows you to put a code in it, then send a remoteFunction/Event.
Send the inputted combination to the server and keep a table of players combinations in a server script then compare the inputted one to the one in the table (not valueInstances cause exploiters can read those)
well more like they can make an code combination, and etc. my point is that every time i try an method for the locker itâs either an error or the yellow one(inifte vli idk how to say it)
Iâm gonna assume the yellow one is you trying to do :WaitForChild() with no timeout on an instance that is not guaranteed to be there
For the playerâs to make a combination you need a different text box when they go to claim the locker and then you save the combination and define the player as the owner with a Object value or something like that
StarterGui clones the Guis into playerâs when they respawn and a Gui is set to ResetOnSpawn=false, Remember that to get the actual playerGui you need to do game.Players.LocalPlayer.PlayerGui, but yeah youâre correct on that.
Youâll need connections to the Click Detector on the lockers so that would be something like
local lockers= --Preferably a Folder containing every locker
for _,locker in lockers:GetChildren() do
locker.ClickDetector.MouseClick:Connect()
end
Then when you show the text bow have a GuiButton to fire the event sending the combination and locker (player is send by default in remote events, no variable needed for them)
i tried, it does let me click but the part (aka the doorpart) wonât be able to close/open whenever i click it or the gui wonât pop up?( i am currently watching youtube to see if something will help)
local Locker = script.Parent
local ClickDetector = Locker:WaitForChild(âClickDetectorâ)
local CombinationPrompt = Locker:WaitForChild(âCombinationPromptâ)
local CombinationInput = CombinationPrompt:WaitForChild(âTextBoxâ)
local Opened = Locker:WaitForChild(âOpenedâ)
local PlayerClaimed = nil
local function onLockerClicked(player)
if PlayerClaimed == nil or PlayerClaimed == player then
â Player hasnât claimed the locker or is the current owner
if Opened.Value then
â Locker is open, so close it
Opened.Value = false
else
â Locker is closed, so open it
Opened.Value = true
end
else
â Another player is currently using the locker
print(âThis locker is currently in use by another player.â)
end
end
local function onCombinationChanged(player)
if PlayerClaimed == nil then
â Player hasnât claimed the locker yet, so claim it
PlayerClaimed = player
print(player.Name ⌠" has claimed the locker.")
else
â Player has already claimed the locker, so notify
print(âYouâve already claimed this locker.â)
end
end
ClickDetector.MouseClick:Connect(function(player)
if CombinationInput.Text ~= ââ then
onCombinationChanged(player)
CombinationInput.Text = ââ â Clear the input after setting the combination
else
onLockerClicked(player)
end
end)
Locker.ChildAdded:Connect(function(child)
if child.Name == âCombinationPromptâ then
child.ChildAdded:Connect(function(innerChild)
if innerChild.Name == âTextBoxâ then
innerChild.FocusLost:Connect(function(enterPressed)
if enterPressed then
onCombinationChanged(game.Players:GetPlayerFromCharacter(Locker))
end
end)
end
end)
end
end)
You never added the part where the UI pops up, or when the door opens/closes. Thereâs also loads of weird characters, which you canât use when coding. For example ââ and â. Instead of using these characters, use ââ and â otherwise your script wonât work.
Wrap your code with " ``` " at the start and end to make it more readable, you donât want a script for every locker you have, that will just be horrible performance wise, impossible to edit all of them at once and frustrating, you can put a script on ServerScriptService and get every locker from there
local lockers --A folder containing every locker for organization and simplicity sake
local lockerEvent--A RemoteEvent/UnreliableRemoteEvent
local function lockerClicked(player,locker)
if not locker.Owner.Value then --Make a object/string value to store the Owner, this means the value is nil
return --and we return, aka finish the function, player will be prompted to get ownership clientside
end
if locker.Owner.Value==player then--or Player.Name if you use a string value
if locker:GetAttribute("Open")==true then
--Logic to close it
locker:SetAttributte("Open",false)
else --Locker is closed
--Logic to open it
locker:SetAtributte("Open",true)
end
else
--Player is not the owner
end
end
for _,locker in pairs(lockers:GetChildren()) do
locker.ClickDetector.MouseClick:Connect(function(player)--We need an anonymus function because we have to pass the locker value
lockerClicked(player,locker)
end)
end
lockerEvent.OnServerEvent:Connect(function(player,locker)
if locker.Owner.Value then return end --Locker is already claimed, just a sanity check
locker.Owner.Value=player --or Player.Name if string value
end)
Now on a local script (for this example i do like itâs under the Gui):
local lockerEvent --Again get you event here
local lockers --Locker folder again
local Gui=script.Parent:WaitForChild("CombinationFrame") --Asumming this is the ScreenGui, and getting the container of the Gui elements , name is whatever you name it
for _,locker in pairs(lockers:GetChildren()) do
locker.ClickDetector.MouseClick:Connect(function()
if not locker.Owner.Value then
Gui.TextBox.Visible=true
Gui.TextButton.Activated:Connect(function()
lockerEvent:FireServer(locker)
Gui.TextBox.Visible=false
end)
end
end)
end
This is not all you need but this should let you claim lockers