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)
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
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.