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)
The script won't run because when the script is put into a tool that the client has, it wont run on the server, only the client. Here's how to properly put it back into serverstorage:
PUT THIS IN SERVERSCRIPTSERVICE
game.Players.PlayerRemoving:Connect(function(client) local tool = client.Backpack["Room 201"] -- or whatever the name of your tool is if tool == nil then local char = client.Character local allChildren = char:GetChildren() for i = 1, #allChildren do if allChildren[i].IsA("Tool") then if allChildren[i].Name == "Room 201" then allChildren[i].Parent = game.ServerStorage elseif allChildren[i].Name == "yeyt" then -- or whatever other weapons you have allChildren[i].Parent = game.ServerStorage end end end end tool.Parent = game.ServerStorage end)
Props to @Prestory for helping me with this answer