Creating a changing room system

Hiya. I’m currently making a changing room/keycard system. I’ve developed a system but it does not work properly. Only one of the keycards work. Here is what I mean below.

Server Script

for _,ChangingRoomClaimers in pairs(ChangingSystem.Claimers:GetDescendants()) do
	function OnProximityActivated(Player)
		local NewKeycard = ServerStorage.ServerTools.Keycard:Clone()
		NewKeycard.Parent = Player.Backpack
		NewKeycard.ChangingRoomNumber.Value = ChangingRoomClaimers:WaitForChild("ChangingRoom").Value
	end
	
	if ChangingRoomClaimers:IsA("Part") then
		local ProximityPrompt = ChangingRoomClaimers:WaitForChild("ProximityPrompt")
		ProximityPrompt.Triggered:Connect(OnProximityActivated)
	end
end

Keycard Handler (Inside the tool)


local Tool = script.Parent
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer

local ChangingSystem = workspace.Misc.ChangingSystem
local ChangingRooms = ChangingSystem.ChangingRooms
local Claimers = ChangingSystem.Claimers

for _,ChangingRoomStatus in pairs(ChangingRooms:GetDescendants()) do
	function OnToolEquipped()
		local ChangingRoomNumber = Tool:WaitForChild("ChangingRoomNumber")
		if ChangingRoomStatus.Name == ChangingRoomNumber.Value then
			ChangingRoomStatus.Transparency = .4
		end
	end
	function OnToolUnEquipped()
		local ChangingRoomNumber = Tool:WaitForChild("ChangingRoomNumber")
		if ChangingRoomStatus.Name == ChangingRoomNumber.Value then
			ChangingRoomStatus.Transparency = 0
		end
	end
end

Tool.Equipped:Connect(OnToolEquipped)
Tool.Unequipped:Connect(OnToolUnEquipped)

Are there any errors in the output?

No there aren’t any outputs from either script.

So do both tools have the same exact server and client script?

I’d assume considering I’ve cloned them all

So is there a place in the script where it tells which door to turn transparent and cancollide off?

casue thats obviously whats not working

Yes, It says in the script to do that.

Yeah but where exactly in the script?

if ChangingRoomStatus.Name == ChangingRoomNumber.Value then
			ChangingRoomStatus.Transparency = .4

Alright well now that we have dumbed it down to these lines, its obvious that the if statement isnt true, are you sure the name is equal to the value

Yes; I’ve triple checked. I’ve deleted one the one that is working and then the one that wasn’t working was then working.

Is this a string?
image

you are making the functions inside of the loop so it gets overridden each loop
put the functions outside of the loop and put the loop inside of the functions

1 Like

It’s a string value yes. I tried using an object value originally but it didn’t work.

Ah, I see. I’ll try that. I appreciate that.

This code appears to be building a changing room system. Specifically, the server-side script loops through all the descendants of an object named ChangingSystem.Claimers and adds a ProximityPrompt event to each descendant. When a player triggers the ProximityPrompt event, the server creates a new Keycard and places it in the player’s backpack.

The client script loops through all descendants of an object named ChangingSystem.ChangingRooms and adds two event handlers: OnToolEquipped and OnToolUnEquipped. When the player equips the tool, the OnToolEquipped event handler checks if the ChangingRoomNumber property of the Keycard in the player’s hand matches the name of the current changing room. If it matches, then the transparency of the changing room is set to 0.4; if it does not match, then no action is taken. When the player unloads the tool, the OnToolUnEquipped event handler restores the transparency of the changing room to 0.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.