Tool stops replicating to server after respawning

Hello.
I’m trying to make a weapon switching system. It works when I first spawn in, but after dying and respawning, it doesn’t seem to replicate to the server. Here’s the code for the client;

function changeWeapon(tool)
	
	print("weapon changed")
	
	if player.Character:WaitForChild("Humanoid").Health <= 0 then
		warn("Player is dead. Weapon won't be changed")
		return
	end
	
	-- move things around to make space for the new tool.
	if tool then
		local currentTool = character:FindFirstChildOfClass("Tool")
		if currentTool then
			character:FindFirstChild("WeaponInfo").Parent = currentTool
			currentTool.Parent = player.Backpack
		end
		tool.Parent = character
		weaponInfo = tool.WeaponInfo
		tool.WeaponInfo.Parent = character
	end
	weaponId = weaponInfo.WeaponId.Value

	if weaponModel then weaponModel:Destroy() end
	if reloadTask then task.cancel(reloadTask) end

	weaponModel = weaponIdInfo[weaponId].WeaponModel:Clone()

	local reloadSound = playingSounds["Reload"]
	if reloadSound then
		reloadSound:Stop()
		reloadSound:Destroy()
	end

	local tool = character:FindFirstChildOfClass("Tool")
	if tool then
		for _, part : BasePart in pairs(tool:GetDescendants()) do
			if part:IsA("BasePart") then
				part.LocalTransparencyModifier = 1
			elseif part:IsA("ParticleEmitter") then
				part.Transparency = NumberSequence.new(1)
			end
		end
	end

	weaponModel.Parent = workspace.ignore

	animator = weaponModel.AnimationController.Animator
	animations = quickFunctions.LoadAllAnimations(weaponModel.Animations.Viewmodel, animator)

	weaponModelOffset = originalModelOffset * CFNew(0, -2, 0) * CFAngles(math.pi/2, math.pi/4, 0)
end

I can try to send specific parts of either server or client code. There’s a lot of code and it’s really hard to track the source of the issue, so you might need to describe what part specifically. I checked if the server was equipping the weapon at all, and it isn’t. I don’t know much about replicating tools, so any help would be very much appreciated.

1 Like

If you could send a file for us to test that would be better. The weird thing I see is that you do character:FindFirstChildOfClass(“Tool”) twice, and reassign tool. Are you trying to make your own custom hotbar system?

Yeah, I’m trying to make a custom hotbar system. Here’s the file;
quake game testing.rbxl (1.2 MB)

So I’ve been testing it, crashed a few times. I don’t really like how some of the stuff is setup like destroying the character, but whatever floats your boat ig. So the issue is that you are parenting the tools from the client, but I’m not entirely sure why it works in the first place. You should probably switch it over to just use a remote event from the changeWeapon function and remove that .ChildAdded for a remote event connection in the ServerHandler.

I thought that maybe Roblox’s replication would be better, but I guess I’m better off using remote events. I don’t really know how to properly unload the character while still keeping the workspace loaded and visible (I’m planning to make a game menu later on), so I ended up just destroying the character. If you have any other ideas on how to do it, please tell me.
Anyways, I’ll just use remote events. Thanks again for the help.

You can go to Game > Players.CharacterAutoLoads and turn that off if you don’t want players automatically spawning. Good luck with your remote events!

1 Like