Hello I am making a LocalScript where you keep your items in your backpack after dying, I don't want to use StarterGear as it is uneccesarily complicated.

My studio crashes after the player.CharacterAdded event.

repeat wait() until game:GetService("Players").LocalPlayer.Character

local player = game:GetService("Players").LocalPlayer
local hum = player.Character:WaitForChild("Humanoid")
local bp = player:WaitForChild("Backpack")
local tools = {}


bp.ChildAdded:Connect(function(obj)
	if obj:IsA("Tool") then
		table.insert(tools,obj)
	end	
end)
bp.ChildRemoved:Connect(function(obj)
	if obj:IsA("Tool") then
		for i,tool in pairs(tools) do
			if tool == obj then
				table.remove(tools,i)
			end
		end
	end
end)

player.CharacterAdded:Connect(function()
	for i,tool in pairs (tools) do
		local cloneTool = tool:Clone()
		cloneTool.Parent = bp
	end
end)

6 comments

0

Maybe try replacing first line with workspace:WaitForChild(game:GetService("Players").LocalPlayer.Name)

0

didnt work

0

I really do not see how this script should crash your studio. Are you sure this is not happening because of another script? Also, you must do this server-sided

0

why cant i do it client sided, this is a local script

0

if you do it client sided the server wont realize youve done a single thing and if one of these tools does damage it will only do it for the client aka wont kill other players

0

you should NEVER do workspace:WaitForChild(game:GetService("Players").LocalPlayer.Name), use game:GetService("Players").LocalPlayer.Character or game:GetService("Players").LocalPlayer.CharacterAdded