You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
i want to try and unequip all the player’s tools even the one the player has equipped once the player’s leave ( to be exact i want to unequip the tools before i save something in the tools with data stores ) -
What is the issue? Include screenshots / videos if possible!
the issue is i only got it to work if the player doesn’t have any tools equipped if the player does have a tool equipped and leaves the game then none of the data of that tool would save. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
i tried to use “:UnequipTools()
” but I’m usingplayeradded
andplayerremove
events so that doesn’t work since the character has already been removed. I’ve been trying to figure out a way to useCharacterRemoving
but it keeps activating after the data save (which doesn’t save the tool the player has equipped).
local function save(player)
if not RunService:IsStudio() then --- set to not save in studio
return
end
print("SavingData")
local colorsaved = colortable(player)
local success, errormessage = pcall(function()
local PlayerUserId = 'Player_'.. player.UserId
print("DataSaved")
ColorStorage:SetAsync(PlayerUserId, colorsaved)
end)
end
Players.PlayerAdded:Connect(function(player)
load(player)
end)
game.Players.PlayerRemoving:Connect(save)
game:BindToClose(function()
for _, player in ipairs(game.Players:GetPlayers()) do
save(player)
end
end)
I’ve also found this piece of code on the internet somewhere, i don’t really know how to add it to main script since this would activate after the data saved
Player.CharacterRemoving:Connect(function(Character)
Character:WaitForChild("Humanoid"):UnequipTools()
print("ToolsUnequiped")
end)