Boolvalue player assigning issue

Hey, I have this server script in ServerScriptService:

game.Players.PlayerAdded:Connect(function(player)
	local humanoid = workspace:WaitForChild(player.name):WaitForChild("Humanoid")

	local disco = Instance.new("BoolValue", humanoid)
	disco.Name = "canpush"
	disco.Value = true
	print(disco.Parent)
end)

It is sometimes ignored and the game doesn’t assign the players humanoid with the boolvalue, but sometimes it does - does anyone know the solution?

The script is supposed to insert a boolvalue inside game.Workspace.EveryPlayerThatJoins.Humanoid.canpush

game.Players.PlayerAdded:Connect(function(player)
	playe.CharacterAdded:connect(function()
        local humanoid = player.Character:WaitForChild("Humanid")
	local disco = Instance.new("BoolValue", humanoid)
	disco.Name = "canpush"
	disco.Value = true
	print(disco.Parent)
        end)
end)

Perhaps they died?

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function()
	   local humanoid = workspace:WaitForChild(player.name):WaitForChild("Humanoid")
	    local disco = Instance.new("BoolValue", humanoid)
	    disco.Name = "canpush"
	    disco.Value = true
	    print(disco.Parent)
    end)
end)
1 Like

Oh…yeah - I didn’t think it would be removed when the player has died, I’ll try it,.

Not removed, when the player respawn they are given a completely fresh character.

1 Like

I see, thanks for the support - honestly wouldn’t be able to figure it out

There’s a few issues with this, the .CharacterAdded event’s parameter points/refers to the character model itself which was added, you don’t need to use the player’s name to index the workspace container for that player’s character. Additionally, the 2nd argument of Instance.new() should be avoided when assigning values to the instanced object’s other properties.

local players = game:GetService("Players")

players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local humanoid = character:WaitForChild("Humanoid")
		local disco = Instance.new("BoolValue")
		disco.Name = "canpush"
		disco.Value = true
		disco.Parent = humanoid
	end)
end)
1 Like

Thank you, I wasn’t aware of this.