1 time player drops materials 2 time doesn't work

this bug i have discovered in the previous post here the example
robloxapp-20231017-2152248.wmv (3.8 MB)

so idk is all in the server and here the reference:

Players.PlayerAdded:Connect(function(player)
	debounceTable[player] = false
	for _, v in pairs(script.PlayerData:GetChildren()) do
	v:Clone().Parent = player
	end
	
	local character = player.Character or player.CharacterAdded:Wait()
	
	character:WaitForChild("Humanoid").Died:Connect(function()
		for _, v in pairs(player.Materials:GetChildren()) do
			if v:IsA("IntValue") and v.Value ~= 0 then
				DropModule.SpawnDrops(v.Name, character.HumanoidRootPart.Position, v.Value, 7)
				v.Value = 0
			end
		end
	end)
end)

if someone has it thank you for the support :wink:

1 Like
Players.PlayerAdded:Connect(function(player)
	debounceTable[player] = false
	for _, v in pairs(script.PlayerData:GetChildren()) do
	v:Clone().Parent = player
	end
	
	Player.CharacterAdded:Connect(function(character)
		character:WaitForChild("Humanoid").Died:Connect(function()
			for _, v in pairs(player.Materials:GetChildren()) do
				if v:IsA("IntValue") and v.Value ~= 0 then
					DropModule.SpawnDrops(v.Name, character.HumanoidRootPart.Position, v.Value, 7)
					v.Value = 0
				end
			end
		end)
	end)
end)

the problem with this is that character doesn’t update when the player dies, i.e. it works once, but when the character dies, a new one spawns and the character variable doesn’t update, the connection is severed. To fix this you need to add a CharacterAdded event.

thank you i didn’t remember about the characterAdded function

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