So I wanted to make a key return script for a resort so the checkin system wouldn't copy keys but move them so no duplicates go to players. Anyways thats not important but whats important is that my script doesn't return the key but it also doesn't return any errors so I don't know what to do. I have been trying to fix it for 2 days now but I have no clue what to do.
So a little idea on how it works: The script is placed inside of the tool (for example lets say the tool: Room 201) The thing is if the tool's parent isn't ServerStorage is checks if the player that left had any keys. So the scripts in the keys execute. If the player that left had a key, then that key should return to the server storage.
game.Players.PlayerRemoving:Connect(function(plr)
local FKey = script.Parent
if FKey.Parent ~= game.ServerStorage then
if plr.Name == script.Parent.Parent.Parent.Name then -- Targets player on game.Players
local BP = script.Parent.Parent
if BP then
local KeyN1 = script.Parent
if KeyN1 then
if KeyN1.Parent == BP then KeyN1.Parent = game.ServerStorage -- Assumes the key is in the backpack
print("Key Returned")
elseif KeyN1.Parent ~= BP then -- if it isn't in the backpack we search in the players character
local Char = game.Workspace:FindFirstChild(plr.Name)
if Char then local Key = Char:FindFirstChild(script.Parent.Name) -- Searches for the specific key
if Key then Key.Parent = game.ServerStorage
print("Key returned")
end
end
end
end
end
else return end
else return end
end)

7 comments
Can you state what this script is a child of and what its hierarchy is? For example, the script being game.Workspace.Model1.CoolPart.Script
Well it depends. It starts in game.ServerStorage.Room 201.Script
Then it gets into a players backpack. So when he leaves it goes back into server storage
So the main thing is the tool being Room 201 and the script is in it.
oh ok
does the tool show up in the player's backpack?
yes