Help with locker script

18:49:08.216 ServerScriptService.Script:29: attempt to index nil with ‘OnServerEvent’ - Server - Script:29 this means there isn’t a Remote Event

18:49:11.868 Players.Acespacesss.PlayerGui.ScreenGui.LocalScript:8: attempt to call missing method ‘GetChildren’ of table - Client - LocalScript:8 Did you use GetChildren() when you defined the variable? it should be an instance not a table

  1. yeah 2. i tried- but now i have put the script normally back how you told me to

Paste the script and use preformated text please, it’s the </> or Ctrl+E shortcut

server script 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

local lockers=game:GetService("ServerStorage"):WaitForChild("Lockers")
for _,locker in pairs(lockers:GetChildren()) do
lockerEvent.OnServerEvent:Connect(function(player)
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)

local script

``local lockerEvent --Again get you event here``
``local lockers --Locker folder again``


``local Gui=script.Parent:WaitForChild("CombinationFrame")``

``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``

You didn’t define it on server side, and player cannot read ServerStorage, put a Folder on workspace, parent the locker model to it and make the lockers variable on both scripts equal that folder

ohh okay, i get it(i am sleepy rn as it’s 7pm here and then i can’t think straight my excuses for that)

It’s fine, we live and we learn

  19:11:33.293  High school Locker @ 10 Dec 2023 19:11 auto-recovery file was created  -  Studio
  19:11:35.337  ServerScriptService.Script:29: attempt to index nil with 'OnServerEvent'  -  Server - Script:29
  19:11:35.337  Stack Begin  -  Studio
  19:11:35.337  Script 'ServerScriptService.Script', Line 29  -  Studio - Script:29
  19:11:35.337  Stack End  -  Studio
  19:11:41.655  Players.Acespacesss.PlayerGui.ScreenGui.LocalScript:7: attempt to index nil with 'GetChildren'  -  Client - LocalScript:7
  19:11:41.656  Stack Begin  -  Studio
  19:11:41.656  Script 'Players.Acespacesss.PlayerGui.ScreenGui.LocalScript', Line 7  -  Studio - LocalScript:7
  19:11:41.656  Stack End  -  Studio

what is wrong with the code :sob: i have put the serverstorage to workspace-

local script


local lockerEvent --Again get you event here
local lockers --Locker folder again


local Gui=script.Parent:WaitForChild("CombinationFrame") 

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

serverscript

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


local lockers=game:GetService("Workspace"):WaitForChild("Lockers")
for _,locker in pairs(lockers:GetChildren()) do
	lockerEvent.OnServerEvent:Connect(function(player)
		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)

this is the code rn-

You still didn’t add a Remote Event, so when you try to connect the .OnServerEvent it errors, and i said to put the folder in workspace, ServerScriptService and ServerStorage don’t replicate over to the client

OH- okay okay i need coffeeee helpp- :sob:

lockers and lockerEvent are never defined, so replace every mentions of them with the folder or set the variable

local lockers=workspace:WaitForChild("Lockers")
local lockerEvent= --You have to create a remoteEvent on replicated storage and then make it equal this

i made an remotevent called OnServerEvent now- i hope it works now

A RemoteEvent is an instance, .OnServerEvent is a RBXScriptSignal

Since the name doesn’t really matter a lot as long as everything is connected correctly it should work

1 Like

yeah true, i will try the gui now, because that’s the only thing left

  19:37:12.695  Owner is not a valid member of Model "Workspace.Lockers.locker"  -  Client - LocalScript:10
  19:37:12.696  Stack Begin  -  Studio
  19:37:12.697  Script 'Players.Acespacesss.PlayerGui.ScreenGui.LocalScript', Line 10  -  Studio - LocalScript:10
  19:37:12.697  Stack End  -  Studio
 at this line there is something wrong but idk what- 	if not locker.Owner.Value then (what else is gonna not valid to my model?-)

Add an ObjectValue on the locker and name it “Owner”

19:43:33.133 TextBox is not a valid member of Frame “Players.Acespacesss.PlayerGui.ScreenGui.CombinationFrame” - Client - this came up as soon i tried again :sob: ************

I guess it’s progress, change that for your text box instance

i did and yet still the same error