Tool Saving Problem

This is the script that gives players tools:

game.ReplicatedStorage.ToolEvents.TeddyEvent.OnServerEvent:Connect(function(player)
	if player.leaderstats.Coins.Value >= 25 then
		player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - 25
		game.ServerStorage.Tools.Teddy:Clone().Parent = player.Backpack
	end
end)

game.ReplicatedStorage.ToolEvents.DryerEvent.OnServerEvent:Connect(function(player)
	if player.leaderstats.Coins.Value >= 500 then
		player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - 500
		game.ServerStorage.Tools.BlowDryer:Clone().Parent = player.Backpack
	end
end)

game.ReplicatedStorage.ToolEvents.HookEvent.OnServerEvent:Connect(function(player)
	if player.leaderstats.Coins.Value >= 750 then
		player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - 750
		game.ServerStorage.Tools.GrappleHook:Clone().Parent = player.Backpack
	end
end)

idk if that has anything to do with it. I don’t think there are any other scripts intefering

do all tools get lost when you die holding it or just the ones with the DontSave attribute?

No it’s any tool that I’m holding.

are there any errors? i just tested the script and it doesnt lose the tool when you’re holding it.
also did you delete the script you originally posted? the one on the first post

No I’m pretty sure the original script is still there.

I also unfortunately don’t see any errors.

delete the original script, and instead use the 2 i gave you.

I have 2 scripts in serverscriptservice. One is called SaveTools and the other is called SaveTools2.

SaveTools:

for _,tool in pairs(game:GetService('StarterPack'):GetChildren()) do
	if not tool:IsA('Tool') then continue end
	if not tool:GetAttribute('UniqueID') then
		tool:SetAttribute('UniqueID', game:GetService('HttpService'):GenerateGUID(false))
	end
end

game:GetService('Players').PlayerAdded:Connect(function(plr)
	plr.DescendantAdded:Connect(function(newTool)
		if newTool:IsA('Tool') and newTool.Parent == plr.Backpack then
			if newTool:GetAttribute("DontSaveOnDeath") then
				return
			end

			if not newTool:GetAttribute('UniqueID') then
				newTool:SetAttribute('UniqueID', game:GetService('HttpService'):GenerateGUID(false))
			end

			for _,existingTool in pairs(game:GetService('StarterPack'):GetChildren()) do
				if existingTool:IsA('Tool') then
					if existingTool:GetAttribute('UniqueID') == newTool:GetAttribute('UniqueID') then
						return
					end
				end
			end

			local newClone = nil
			for _,existingTool in pairs(plr.StarterGear:GetChildren()) do
				if existingTool:IsA('Tool') then
					if existingTool:GetAttribute('UniqueID') == newTool:GetAttribute('UniqueID') then
						newClone = existingTool
						break
					end
				end
			end
			if not newClone then
				newClone = newTool:Clone()
				newClone.Parent = plr.StarterGear
			end

			newTool.AncestryChanged:Connect(function()
				if not plr:FindFirstChild('Backpack') then return end
				if newTool.Parent ~= plr.Backpack and newTool.Parent ~= plr.Character then
					local hum = plr.Character:FindFirstChildOfClass('Humanoid')
					if hum then
						if hum.Health > 0 then
							newClone:Destroy()
						end
					end
				end
			end)
		end
	end)
end)

SaveTools2:

local toolfolder = game:GetService("ServerStorage"):FindFirstChild("SaveTools")
local dss = game:GetService("DataStoreService")
local saveddata = dss:GetDataStore("SaveData")

game.Players.PlayerAdded:Connect(function(player)
	local tooldata = saveddata:GetAsync(player.UserId)

	local backpack = player:WaitForChild("Backpack")
	local startergear = player:WaitForChild("StarterGear")

	if tooldata ~= nil then
		for i, v in pairs(tooldata) do
			local RSTool = toolfolder:FindFirstChild(v)
			if RSTool then
				toolfolder[v]:Clone().Parent = backpack
			end
		end
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local tooltable = {}

	for i, v in pairs(player.StarterGear:GetChildren()) do
		-- preferable check if v is a tool
		table.insert(tooltable, v.Name)
	end
	if tooltable ~= nil then
		saveddata:SetAsync(player.UserId,tooltable)
	end
end)

These are the ones you game me, right?

yes it should be like that, remove the original script if its still there. test again

These are the only two save tools scripts. The original was deleted a while ago. The same thing happens. Jump off the map, the tool saves. Jump off the map while holding the tool, it gets deleted.

okay i just tested it and yes it doesnt save if you jump in the void, probably because the void is getting rid of your character before setting your humanoids health to 0, you can maybe fix this if you unequip the tools when the character reachs a certain height (-400), or i’d just not be concerned if theres not alot of jumping into the void in your game

The only way you can die in this game is falling in the void which is a problem. Maybe I could just put a part that teleports you to the spawn. Thanks

1 Like

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